How do I divide image into overlapping blocks size

2 views (last 30 days)
In a paper, it has been said that they have computed frequency over a discrete grid of granularity using 15x15 windows. Consulting my friend, it means overlapping blocks centered at each 8 pixels, that its length and width would be 15 pixels.
How can I do it with blockproc()? Or is there any other useful ways?
  2 Comments
surendra hima
surendra hima on 13 Feb 2017
I WANT TO DIVIDE AN IMAGE HAVING SIZE 512X512.I WANT TO DIVIDE IT INTO OVERLAPPING BLOCKS. HERE IS MY FOLLOWING CODE clc; clear all; close all; I=imread('surya.jpg'); figure; imshow(I); I1 = rgb2gray(I); figure; imshow(I1); I2=im2bw(I1); figure; imshow(I2); [LL,LH,HL,HH]=dwt2(I2,'haar'); figure('units','normalized','outerposition',[0 0 1 1]) imshow(LL);title('LL band of image'); n=size(LL,1); m=size(LL,2); dl=6 ; % number of vertical portions dc=6 ; % number of horizontal portions a=fix(n/dl); b=fix(m/dc); n0=1; portion=[]; ii=0; for k=linspace(a,n,dl) m0=1; ii=ii+1; jj=0; for p=linspace(b,m,dc) jj=jj+1; im1=LL(n0:k,m0:p,:); portion{ii,jj}=im1; m0=p+1; end n0=k+1; end portion ii=0; for k=1:dl for p=1:dc ii=ii+1; subplot(dl,dc,ii); imshow(portion{k,p}); end end figure('units','normalized','outerposition',[0 0 1 1]) imshow(HH);title('HH band of image'); c=size(HH,1); d=size(HH,2); dl=6 ; % number of vertical portions dc=6 ; % number of horizontal portions e=fix(c/dl); f=fix(d/dc); c0=1; portion=[]; ll=0; for h=linspace(e,c,dl) d0=1; ll=ll+1; oo=0; for g=linspace(f,d,dc) oo=oo+1; im2=HH(c0:h,d0:g,:); portion{ll,oo}=im2; d0=g+1; end c0=h+1; end portion ll=0; for h=1:dl for g=1:dc ll=ll+1; subplot(dl,dc,ll); imshow(portion{h,g}); end end
Image Analyst
Image Analyst on 13 Feb 2017
surendra, is this an answer for Klara? If so put it as an Answer below. If it's a question from you, then ask the question (currently there is no question there) in a new question separate from this one.

Sign in to comment.

Accepted Answer

Joseph Cheng
Joseph Cheng on 27 Mar 2014
If blockproc is not working out due to 8, why not use a a nested for loop to carve out the 15x15 block?
[row col]=size(Image)
for i=8:8:col-7
j = 8:8:row-7
block=Image(j-7:j+7,i-7:i+7)
end
end

More Answers (1)

Image Analyst
Image Analyst on 27 Mar 2014
You need to specify a negative BorderSize to have the window locations overlap instead of tile. I think it might be something like
B = blockproc(A, [8, 8], fun, 'BorderSize', [-3, -3]);
but that will be a window size of 14 by 14. The problem is that you're using 8. Almost all sliding window functions use an odd number so that the output image is not shifted a half pixel relative to the input image.
  1 Comment
Klara
Klara on 27 Mar 2014
Edited: Klara on 27 Mar 2014
Trying with
fun =@(block_struct) block_struct.data
Sorry, it gives me "invalid border size" error. Since the border size should be positive.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!