How to divide image matlab into overlapping block

烈酒焚心 提交于 2019-12-23 05:26:15

问题


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


回答1:


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



回答2:


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




回答3:


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



回答4:


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;`


来源:https://stackoverflow.com/questions/15195030/how-to-divide-image-matlab-into-overlapping-block

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!