Block structures and image processing

Hi,
I'm using a matlab code to divide the pixels of the image into blocks and return the average. at the beginning of the program I introduce the input value of the image pixels to be
XL=1;
XR=120;
YU=1;
YD=120;
then i introduced the new dimensions to divide the whole pixels into [10 10] size block
XC=(XR-XL+1)/10;
YC=(YD-YU+1)/10;
and this is how I used block pro function in my program:
PC_S_A=reshape(PC_S_A,120,120);
PC_S_A=PC_S_A';
PC_S_A=PC_S_A(YU:YD,XL:XR);
fun = @(block_struct) mean2(block_struct.data);
PC_S_A = blockproc(PC_S_A,[10 10],fun);
pic_temp=reshape(PC_S_A,1,12*12);
pic_tank_M=[pic_tank_M;pic_temp];
the program is working perfectly, but I want to modify the code with a loop, I want to force the function to combine the first 10x10 pixels as one block , then I want the starting pixel for the second block to be the middle one in the first block. like in the image.
in other words I want the blocks to be shifted 5 pixels for the the starting pixel of previous block.
any suggestion how to do that???

Respuestas (1)

Walter Roberson
Walter Roberson el 18 de Jul. de 2016
You will indeed need to loop yourself.
blockproc() has provisions for sliding window, by specifying BorderSize. The blocksize you specify in the second parameter of blockproc should be how far over you want to shift each time; because you want to shift by 5, that would require a blocksize of [5 5]. Then the BorderSize says how rows and columns to put above and below, and left and right. As the documentation indicates
The size of each resulting block will be: [M + 2*V, N + 2*H]
because V and H are added to both sides. But V and H are restricted to integers, so if you start with a 5 x 5 block and add an even amount, you are going to end up with a block that is odd-valued on each side, whereas you wanted to end up with a 10 x 10 block. So you will not be able to do this using blockproc() -- not unless you are willing to shift by 4 or 6 each time instead of by 5, or if you are willing to use 9 x 9 or 11 x 11 outer blocks instead of 10 x 10.

3 comentarios

Mai Khaleel
Mai Khaleel el 18 de Jul. de 2016
My image size in 120 x 120 pixel, I used to divide this image into 24 x 24 block, each block is 5x5 pixels.and this works perfect in my program. what I want to do is to restrict the jumps of blockproc function and at the same time I want to keep the block size the same. for example the first block will start from pixel number 1 to pixel number 10 (in x and y direction)and give me the first block, I want to force the function to make the 2nd block starting from pixel number 5 (the middle pixel of 1st block) the shift in one direction only, its like at the end I will have a final image with 12x12 blocks wich overlapping each other with 5 pixels. i hope that my question is clear now. and in fact its not important for me the final number of the blocks that i will have. all i care about is how to make a blocks that overlap each other with shifted distance( like 5 pixels or more ) like in the image I attached with my question.
Kevin Semmelink
Kevin Semmelink el 27 de Jun. de 2017
Hi,
I have the same problem. I was wondering if and so how you solved this problem.
Thank you in advance!

Iniciar sesión para comentar.

Preguntada:

el 18 de Jul. de 2016

Comentada:

el 27 de Jun. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by