Syntax for using 'blockproc' command to divide a .jpg image into blocks

1 view (last 30 days)
I have a problem where I need to subdivide the image into smaller blocks. While this is quite easy for gray image by using mat2cell command (input image being 2D array or matrix), same is not true (at least for me now) for color image (being 3D array). I find that 'blockproc' is the proper way to use 'mat2cell' for each layer of the color image. But somehow I am not very comfortable with the explanation of the syntax for using 'blockproc'. It will be very help full if the proper syntax is given to me.

Answers (2)

Walter Roberson
Walter Roberson on 18 Apr 2013
B = 8; %e.g., 8 x 8
ImageBlocks = mat2cell( YourRGBImage, B * ones(1, size(YourRGBImage,1)/B), B * ones(1, size(YourRGBImage,2)/B), size(YourRGBImage,3) );
Note: this will also work for grayscale images.

Bidyut Chakraborty
Bidyut Chakraborty on 19 Apr 2013
Edited: Bidyut Chakraborty on 19 Apr 2013
Thanks Walter, However meanwhile I went along as below:
for h=1:3
c=mat2cell(img(:,:,h),[200 200 200],[200 200 200 200]);
: my other processing on the blocks of layer h = 1 (red) here
:
end
Well I do thank you for the code line that you suggested and I'm sure it will work. However how would I combine these layers (r, g and b) to form the modified image? I actually inserted this line at the end in the above iteration: imgNew(:,:,h) = cell2mat(c); It worked for my purpose. Any comment please Bidyut

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!