Reputation: 1750
I need to divide an image 512*512 into 41*41 overlapping using matlab.In other words, I want to take first a 41*41 block centred in q then I shift by a pixel and I take a 41*41 centered in q+1 and so on.. I can't use Blockproc because it gives a not overlapping block.
thanks to help me
Upvotes: 0
Views: 3795
Reputation: 1
The easiest method to get overlapping blocks is to use im2col() with 'sliding' option.
%Read images one at a time , get overlapping patches of size sz,sz and concatenate it to columns of a matrix.
% LOOP HERE
f=imread([inp_dir files(k).name]);
% extract patches of image
P=[P im2col(f,[sz sz],'sliding')];
% END LOOP HERE
Upvotes: 0
Reputation: 1331
You CAN use BLOCKPROC. It is a bit non-obvious.
Set a block size of [1 1], and then use the 'Border' parameter to specify how big a block you want around each pixel:
>> a
a =
8 1 6
3 5 7
4 9 2
>> blockproc(a, [1 1], @(bs)disp(bs.data),'BorderSize', [1 1 ])
0 0 0
0 8 1
0 3 5
0 0 0
1 6 0
5 7 0
0 3 5
0 4 9
0 0 0
5 7 0
9 2 0
0 0 0
0 0 0
8 1 6
3 5 7
0 8 1
0 3 5
0 4 9
8 1 6
3 5 7
4 9 2
3 5 7
4 9 2
0 0 0
1 6 0
5 7 0
9 2 0
Upvotes: 3
Reputation: 256
First of all declare a variable (Var) to store the image block of blocksize 41*41.Then using the two for loop extract the block of the image.here is the code..
I = imread('cameraman.tif');
[row,col] = size(I);
window = 41;
Var = zeros(1:window,1:window);
for i = 21:row-window
for j= 21:col-window
Var = I(i-20:i+20,j-20:j+20);
end;
end;`
Upvotes: -1
Reputation: 382
Loop it with
block_size = 41;
row_startpos = 1;
col_startpos = 1;
Img = imread('your_image.jpg');
>Loop Begins here
a = Img(row_startpos:block_size,col_startpos:block_size);
row_startpos = row_startpos+row_overlap;
col_startpos = col_startpos+col_overlap;
>Loop Ends here
Add Border check criteria etc
Upvotes: 0