How can i divide an image into Overlapping Blocks without using for loop?
9 views (last 30 days)
Show older comments
Hi all, Lets suppose i have an image of size 64x48, i want to divide it into blocks of size 4x4 (or any size) with an overlap of 1 (or any size less than 4 incase of 4). I tried to read blockproc, but one they need some function to be applied on it which i don't have currently, and second they don't give option of overlapping.
How can i do that?
THanks in advance.
0 Comments
Answers (2)
Adam
on 18 Sep 2014
Edited: Adam
on 18 Sep 2014
myImage = rand(64,48);
x = 1:3:64;
y = 1:3:48;
[X,Y] = meshgrid(x,y);
subImages = arrayfun( @(x,y) myImage(x:min(end,x+3),y:min(end,y+3)), X, Y, 'UniformOutput', false )';
should give you a cell array containing 4*4 overlapping sub-images upto the final one which may be smaller due to the image size.
I tested that in a bit of a rush though so there may be some elements not quite right. Hopefully it gives you an idea though if it isn't a complete answer.
6 Comments
Image Analyst
on 2 Feb 2017
You'd have to write your own code for that since blockproc only works with 2-D images.
Image Analyst
on 18 Sep 2014
Edited: Image Analyst
on 18 Sep 2014
See the FAQ: http://matlab.wikia.com/wiki/FAQ#How_do_I_split_an_image_into_non-overlapping_blocks.3F. Neither of the two methods listed uses blockproc(). I'm pretty sure you can figure out how to adapt it from non-overlapping to overlapping by 1 pixel.
8 Comments
Image Analyst
on 23 Sep 2014
I'm attaching a demo for nlfilter(). See the function called LocalOtsu? Just rename it to whatever you want that describes the operations you want. Then put whatever custom operations you want inside it.
By the way, what you described is just a simple cross correlation and can be done with xcorr2().
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!