How to use block processing for an image?

I am kind of new to Matlab. I am trying to write code that divides an image in non-overlapping blocks of size 3 * 3, and I have to perform the operation of a specific block, for example, get the value of the central pixel of the block and perform some operations. But I don’t know where to start. Using a command like blockproc will not help. Can someone suggest me where to start?

0
image-processing
source share
1 answer

You can easily use blockproc for this: http://www.mathworks.com/help/toolbox/images/ref/blockproc.html

But if this does not work for you, what mistakes do you get?

If you want to do this manually (for example, extracting the central pixel value of each block), you can simply use two loops for this. But keep in mind that this is a rather inelegant and not very fast way to do this ...

image = imread('image.png'); s = size(image); for i=2:3:s(1)-1 for j=2:3:s(2)-1 %% here you have the midpoint of each 3x3 block... %% you could then easily crop the image around it if you %% really need separated blocks... end end 

This is not a very fast way, but ... but it works ...

Hope this helps ...

+1
source share

All Articles