フィルターのクリア

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