필터 지우기
필터 지우기

how to divide an image 512x512 into 4x4 overlapping blocks.

조회 수: 1 (최근 30일)
Sanghamitra Tripathy
Sanghamitra Tripathy 2014년 11월 18일
댓글: Sanghamitra Tripathy 2014년 11월 18일
I have a lena image of 512x512. I want divide the image into 4x4 overlapping blocks, for which i wrote the below code. And i also have to find the no. of 4x4 overlapping blocks. Here I have set a counter to check the no.of 4x4 overlaping blocks. Am i doing it correctly? Please Help.Thanks
[e,f] = size(outImg);
counter=0
for i = 1:e-3
for j = 1:f-3
I = double(outImg((i:i+3),(j:j+3)));
counter=counter+1;
end
end
  댓글 수: 1
Guillaume
Guillaume 2014년 11월 18일
As a piece of advice, use better, more descriptive names for your variables, e.g.
[height, width] = size(inImg);
for row = 1:height-3
for column = 1:width-3
'e' is a particularly bad name, consider the output of the following two lines
1:e-3
1e-3
One character difference, a completely different output. A good source of bugs!

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2014년 11월 18일
Why overlapping? What are you doing with the badly-named I? Nothing. If you want non-overlapping sub-images extracted, you can use indexing or mat2cell. These techniques are shown in the FAQ: http://matlab.wikia.com/wiki/FAQ#How_do_I_split_an_image_into_non-overlapping_blocks.3F
If you want overlapping you can use imfilter(), conv2(), or even blockproc(), but you have to specify some operation, which you haven't done yet.
  댓글 수: 1
Sanghamitra Tripathy
Sanghamitra Tripathy 2014년 11월 18일
편집: Sanghamitra Tripathy 2014년 11월 18일
Here "I" in which i have stored the 4x4 blocks.I have executed the code but i get a very big value for the count (like (e-3)x(f-3)=259081). If i execute the code for 4x4 block for the entire image,doubt was like should i get such big value(i.e no. of 4x4 blocks=259081) Need to cross check with blockproc() then.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Thorsten
Thorsten 2014년 11월 18일
If you do something for N times for M times you do it for N*M times, i.e. for (e-3)*(f-3) times in your example. No need to use a counter, just write
Nblocks = (e-4)*(f-3);
So for a 512x512 image you end up with 259081 blocks.
In your implementation you do not store all the separate blocks in I but just the block for the current i, j, so that after the loop I will be the bottom right 4x4 block in your image. If you sure that you really need to have such a redundant representation of all these blocks, which is roughly 4*4=16 times the size of the image, you can use
I(:,:,counter) = double(outImg((i:i+3),(j:j+3)));
  댓글 수: 1
Sanghamitra Tripathy
Sanghamitra Tripathy 2014년 11월 18일
Thank you all for your comments.It was definitely helped me for writing better codes.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by