Question

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!

Was it helpful?

Solution

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)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top