How can I find local maxima in an image in MATLAB?

后端 未结 5 1618
无人及你
无人及你 2020-12-08 00:54

I have an image in MATLAB:

y = rgb2gray(imread(\'some_image_file.jpg\'));

and I want to do some processing on it:

pic = som         


        
5条回答
  •  Happy的楠姐
    2020-12-08 01:56

    If you have the Image Processing Toolbox, you could use the IMREGIONALMAX function:

    BW = imregionalmax(y);
    

    The variable BW will be a logical matrix the same size as y with ones indicating the local maxima and zeroes otherwise.

    NOTE: As you point out, IMREGIONALMAX will find maxima that are greater than or equal to their neighbors. If you want to exclude neighboring maxima with the same value (i.e. find maxima that are single pixels), you could use the BWCONNCOMP function. The following should remove points in BW that have any neighbors, leaving only single pixels:

    CC = bwconncomp(BW);
    for i = 1:CC.NumObjects,
      index = CC.PixelIdxList{i};
      if (numel(index) > 1),
        BW(index) = false;
      end
    end
    

提交回复
热议问题