How can i divide an image into Overlapping Blocks without using for loop?

6 Ansichten (letzte 30 Tage)
ihsan
ihsan am 18 Sep. 2014
Bearbeitet: KSSV am 22 Dez. 2023
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.

Antworten (2)

Adam
Adam am 18 Sep. 2014
Bearbeitet: Adam am 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 Kommentare
Image Analyst
Image Analyst am 2 Feb. 2017
You'd have to write your own code for that since blockproc only works with 2-D images.

Melden Sie sich an, um zu kommentieren.


Image Analyst
Image Analyst am 18 Sep. 2014
Bearbeitet: Image Analyst am 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 Kommentare
ihsan
ihsan am 23 Sep. 2014
Bearbeitet: KSSV am 22 Dez. 2023
pardon me for being childish. But i can't understand how can i use nfilter in my case. E.g
mat1 = rand(20,16);
mat2= rand(20,16);
Receptive_fieldsize = [4,3];
overlap = 1;
fun = sum(sum(RF_mat1 .* RF_mat2)); % RF_mat1 is taking block of 4x3 from mat1 and same indices from mat2 which becomes RF_mat2.
How can i use this so that i may get output image of size 6x5.
Image Analyst
Image Analyst am 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().

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by