0

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

LearnToGrow
  • 1,656
  • 6
  • 30
  • 53

4 Answers4

3

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
Ashish Uthama
  • 1,331
  • 1
  • 9
  • 14
  • I see that if one can display the data of each block then there can be some control as to how the data is processed. My issue is not the way the image is divided but how the data is concatenated back in the output. There is no control over it and if one needs the output of each block in a specific format. Can I save the blocks individually in a cell maybe? and then process each block individually and then concatenate the results? This would give me more control. – StuckInPhDNoMore Mar 18 '15 at 19:01
  • I also have a question open regarding the above problem of mine here: http://stackoverflow.com/questions/29109241/is-there-any-way-to-control-the-concatenation-of-the-blockproc-output I would appreciate your input. Thank you – StuckInPhDNoMore Mar 18 '15 at 19:02
0

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

Sridutt
  • 382
  • 3
  • 14
0

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
-1

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;`
Ritesh
  • 256
  • 2
  • 13