how to divide an image 512x512 into 4x4 overlapping blocks.
조회 수: 3 (최근 30일)
이전 댓글 표시
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
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
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개)
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)));
참고 항목
카테고리
Help Center 및 File Exchange에서 Computer Vision with Simulink에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!