[Solved] Error using .* Matrix dimensions must agree?


As your input image I is a color image (RGB), the array I is three-dimensional: width-by-height-by-3, because for each pixel you need three values: red, green and blue. The output of butterhp, however, is always width-by-height, so you are trying to multiply a 2D-array times a 3D-array, which fails of course.

Often, processing in grayscale is faster and gets quite good results. To do that, convert the image to grayscale after loading using rgb2gray:

imGrayScale = rgb2gray(I);

If you want to stick with RGB and process each color channel independently, you can replace your multiplication by bsxfun, which applies the element-wise operation (here: @times, i.e. element-wise multiplication) to all elements of fftlogim and f, but “implicitly expanding the dimensions”. That means the w-by-h-by-1 matrix is automatically converted to w-by-h-by-3 so both arrays can be multiplied.

c = bsxfun(@times, fftlogim, f);

1

solved Error using .* Matrix dimensions must agree?