Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
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 comentario
Guillaume
Guillaume el 18 de Nov. de 2014
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!

Iniciar sesión para comentar.

Respuesta aceptada

Image Analyst
Image Analyst el 18 de Nov. de 2014
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 comentario
Sanghamitra Tripathy
Sanghamitra Tripathy el 18 de Nov. de 2014
Editada: Sanghamitra Tripathy el 18 de Nov. de 2014
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.

Iniciar sesión para comentar.

Más respuestas (1)

Thorsten
Thorsten el 18 de Nov. de 2014
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 comentario
Sanghamitra Tripathy
Sanghamitra Tripathy el 18 de Nov. de 2014
Thank you all for your comments.It was definitely helped me for writing better codes.

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by