How can i divide an image into Overlapping Blocks without using for loop?
6 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
Adam
2014-9-18
编辑:Adam
2014-9-18
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 个评论
Image Analyst
2017-2-2
You'd have to write your own code for that since blockproc only works with 2-D images.
Image Analyst
2014-9-18
编辑:Image Analyst
2014-9-18
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 个评论
Image Analyst
2014-9-23
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().
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!