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

后端 未结 5 1639
无人及你
无人及你 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条回答
  •  清歌不尽
    2020-12-08 01:41

    In addition to imdilate, which is in the Image Processing Toolbox, you can also use ordfilt2.

    ordfilt2 sorts values in local neighborhoods and picks the n-th value. (The MathWorks example demonstrates how to implemented a max filter.) You can also implement a 3x3 peak finder with ordfilt2 with the following logic:

    1. Define a 3x3 domain that does not include the center pixel (8 pixels).

      >> mask = ones(3); mask(5) = 0 % 3x3 max
      mask =
           1     1     1
           1     0     1
           1     1     1
      
    2. Select the largest (8th) value with ordfilt2.

      >> B = ordfilt2(A,8,mask)
      B =
           3     3     3     3     3     4     4     4
           3     5     5     5     4     4     4     4
           3     5     3     5     4     4     4     4
           3     5     5     5     4     6     6     6
           3     3     3     3     4     6     4     6
           1     1     1     1     4     6     6     6
      
    3. Compare this output to the center value of each neighborhood (just A):

      >> peaks = A > B
      peaks =
           0     0     0     0     0     0     0     0
           0     0     0     0     0     0     0     0
           0     0     1     0     0     0     0     0
           0     0     0     0     0     0     0     0
           0     0     0     0     0     0     1     0
           0     0     0     0     0     0     0     0
      

提交回复
热议问题