Question

I'm trying to compute a block function between image 1 and 2. In the example below, I'm trying to multiply each block of image 1 with the top left block of image 2

Blocksize = 3;

fun = @(block) block.data .* im2(1:Blocksize, 1:Blocksize);
im3 = blockproc(im1,[Blocksize Blocksize],fun, 'TrimBorder', 1);

I keep getting the Matrix dimensions must agree error, and I don't know why. To my understanding both blocks are 3x3.

Does anyone know what I'm doing wrong?

Was it helpful?

Solution 2

The problem comes when MATALB tries to evaluate the function for the corner blocks. If you go into the blockproc function, you can observe that the error occurs because the getBlock function returns a 3x1 block (?). Therefore, you should set PadPartialBlocks to true.

Blocksize = 3;

fun = @(block) block.data .* im2(1:Blocksize, 1:Blocksize);
im3 = blockproc(im1,[Blocksize Blocksize],fun, 'PadPartialBlocks',1,'TrimBorder', 1);

Also, you mention that you want to multiply with the top right block but in fact you are accessing the top left block.

OTHER TIPS

You can do it just with indexing:

im3 = im1.*im2(mod(0:size(im1,1)-1,BlockSize)+1, mod(0:size(im1,2)-1,BlockSize)+1);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top