This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

imregionalmax

Regional maxima

Syntax

BW = imregionalmax(I)
BW = imregionalmax(I,conn)

Description

example

BW = imregionalmax(I) returns the binary image BW that identifies the regional maxima in grayscale image I. Regional minima are connected components of pixels with a constant intensity value, surrounded by pixels with a lower value.

You optionally can identify regional maxima of 2-D images using a GPU (requires Parallel Computing Toolbox™). For more information, see Image Processing on a GPU.

BW = imregionalmax(I,conn) specifies the pixel connectivity, conn.

Examples

collapse all

Create a simple sample image with several regional maxima.

A = 10*ones(10,10);
A(2:4,2:4) = 22; 
A(6:8,6:8) = 33; 
A(2,7) = 44;
A(3,8) = 45;
A(4,9) = 44
A = 10×10

    10    10    10    10    10    10    10    10    10    10
    10    22    22    22    10    10    44    10    10    10
    10    22    22    22    10    10    10    45    10    10
    10    22    22    22    10    10    10    10    44    10
    10    10    10    10    10    10    10    10    10    10
    10    10    10    10    10    33    33    33    10    10
    10    10    10    10    10    33    33    33    10    10
    10    10    10    10    10    33    33    33    10    10
    10    10    10    10    10    10    10    10    10    10
    10    10    10    10    10    10    10    10    10    10

Find the regional maxima. Note that the result includes the regional maxima at (3,8).

regmax = imregionalmax(A)
regmax = 10x10 logical array

   0   0   0   0   0   0   0   0   0   0
   0   1   1   1   0   0   0   0   0   0
   0   1   1   1   0   0   0   1   0   0
   0   1   1   1   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   1   1   1   0   0
   0   0   0   0   0   1   1   1   0   0
   0   0   0   0   0   1   1   1   0   0
   0   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0   0

Create a 10-by-10 pixel sample image that contains two regional maxima.

A = 10*gpuArray(ones(10,10));
A(2:4,2:4) = 22;    % maxima 12 higher than surrounding pixels
A(6:8,6:8) = 33;    % maxima 23 higher than surrounding pixels
A(2,7) = 44;
A(3,8) = 45;     % maxima 1 higher than surrounding pixels
A(4,9) = 44
A =

    10    10    10    10    10    10    10    10    10    10
    10    22    22    22    10    10    44    10    10    10
    10    22    22    22    10    10    10    45    10    10
    10    22    22    22    10    10    10    10    44    10
    10    10    10    10    10    10    10    10    10    10
    10    10    10    10    10    33    33    33    10    10
    10    10    10    10    10    33    33    33    10    10
    10    10    10    10    10    33    33    33    10    10
    10    10    10    10    10    10    10    10    10    10
    10    10    10    10    10    10    10    10    10    10

Pass the sample image A to imregionalmax. The function returns a binary image, the same size as A, in which pixels with the value 1 represent the regional maxima in A. imregionalmax sets all other pixels in to 0.

regmax = imregionalmax(A)
regmax =

     0     0     0     0     0     0     0     0     0     0
     0     1     1     1     0     0     0     0     0     0
     0     1     1     1     0     0     0     1     0     0
     0     1     1     1     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     1     1     1     0     0
     0     0     0     0     0     1     1     1     0     0
     0     0     0     0     0     1     1     1     0     0
     0     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0     0

Input Arguments

collapse all

Input array, specified as a numeric array of any dimension.

To calculate regional maxima using a GPU, specify I as a gpuArray that contains a 2-D numeric matrix.

Example: I = imread('cameraman.tif');

Example: I = gpuArray(imread('cameraman.tif'));

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

Pixel connectivity, specified as one of the values in this table. The default connectivity is 8 for 2-D images, and 26 for 3-D images.

Value

Meaning

Two-Dimensional Connectivities

4-connected

Pixels are connected if their edges touch. The neighborhood of a pixel are the adjacent pixels in the horizontal or vertical direction.

8-connected

Pixels are connected if their edges or corners touch. The neighborhood of a pixel are the adjacent pixels in the horizontal, vertical, or diagonal direction.

Three-Dimensional Connectivities

6-connected

Pixels are connected if their faces touch. The neighborhood of a pixel are the adjacent pixels in:

  • One of these directions: in, out, left, right, up, and down

18-connected

Pixels are connected if their faces or edges touch. The neighborhood of a pixel are the adjacent pixels in:

  • One of these directions: in, out, left, right, up, and down

  • A combination of two directions, such as right-down or in-up

26-connected

Pixels are connected if their faces, edges, or corners touch. The neighborhood of a pixel are the adjacent pixels in:

  • One of these directions: in, out, left, right, up, and down

  • A combination of two directions, such as right-down or in-up

  • A combination of three directions, such as in-right-up or in-left-down

For higher dimensions, imregionalmax uses the default value conndef(ndims(I),'maximal').

Connectivity can also be defined in a more general way for any dimension by specifying a 3-by-3-by- ... -by-3 matrix of 0s and 1s. The 1-valued elements define neighborhood locations relative to the center element of conn. Note that conn must be symmetric about its center element. See Specifying Custom Connectivities for more information.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Output Arguments

collapse all

Locations of regional maxima, returned as a logical array of the same size as I. Pixels with the value 1 indicate regional maxima; all other pixels are set to 0.

If the regional maxima are computed using a GPU, then BW is returned as a gpuArray that contains a logical matrix of the same size as I.

Data Types: logical

Extended Capabilities

Introduced before R2006a