Search code examples
matlabmatlab-deployment

Woking with colfit in matlab


I wanted to calculate the histogram n local histogram equalisation of an input image, using colfit. But when i run the code i get the following error. ??? Error using ==> ge Matrix dimensions must agree.

Error in ==> colfilt at 135 if all(block>=size(a)), % Process the whole matrix at once.

Error in ==> localhist at 10 z=colfilt(f,[w w],'sliding',@std);

Please provide some insights.


Solution

  • I haven't seen it written on the documentation (neither on help colfilt nor on docs colfilt), but I think you can only use colfilt, as nlfilter, with monochannel images. So that if you try to run the example code provided on help colfilt on a 3-channel image, say:

    I = imread('peppers.png');  % 'peppers.png' is just a demo color image usually provided with matblab
    figure, imshow(I)
    I2 = uint8(colfilt(I,[5 5],'sliding',@mean));
    figure, imshow(I2)
    

    You get the kind of error that you posted:

    Error using >= Matrix dimensions must agree.

    Error in colfilt (line 135) if all(block>=size(a)), % Process the whole matrix at once.

    If you thry this instead, which only takes the first channel (or any other combination of the channels) it will just work

    % which is one of the example images usually provided with matlab
    J = imread('peppers.png');
    I = J(:,:,1);
    figure, imshow(I)
    I2 = uint8(colfilt(I,[5 5],'sliding',@mean));
    figure, imshow(I2)
    

    I hope this helps