Search code examples
matlabimage-processingmatrixmatrix-indexing

What is wrong with this line of MATLAB code?


When I try to run this line of code in MATLAB:

image_arr(i,:,:) = medfilt2(image_arr(i,:,:), [9 9])

it errors:

Error using medfilt2
Expected input number 1, A, to be two-dimensional.

image_arr is an n * x_max * y_max array containing n, x_max by y_max images in grayscale. Is this stored improperly? I have seen mention of x_max by y_max by n arrays in the documentation...

In this case, image_arr is a 29x1536x2048 array, whose members are all of the single type.


Solution

  • Example:

    >> img = rand(5, 100, 200);
    >> size(img(1,:,:))
    ans =
         1   100   200
    

    You wanna get rid of that leading singleton dimension:

    squeeze(img(1,:,:))
    

    or:

    permute(img(1,:,:), [2 3 1])