Block structures and image processing
2 views (last 30 days)
Show older comments
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???
0 Comments
Answers (1)
Walter Roberson
on 18 Jul 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 Comments
Kevin Semmelink
on 27 Jun 2017
Hi,
I have the same problem. I was wondering if and so how you solved this problem.
Thank you in advance!
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!