jonepatr
jonepatr

Reputation: 7809

How do I rasterize an image in Matlab?

I need to rasterize an image in matlab. I have a b/w image and want to chunk it up in 8x8 blocks and get a mean value from every block. Then I want to replace the block with a new block that is made up by ones and zeros, with a amount of ones depending on the mean value from the original block.

Thanks in advance!

Upvotes: 0

Views: 1779

Answers (1)

MatlabDoug
MatlabDoug

Reputation: 5714

This will get you started. It is the downsampled image where each value is between zero and the square of the block size. You are on your own expanding that integer into a sub matrix.

bs = 8
a = imread('trees.tif');
[r,c] = size(a);
d  = imresize(a,[round(r/bs), round(c/bs)]);


figure(1)
imshow(a)
figure(2)
imshow(d)

mv = max(d(:))

d = round(double(d)/double(mv)*bs*bs);

figure(3)
imagesc(d)

Upvotes: 1

Related Questions