# imhmax

Suppress regional maxima in image using H-maxima transform

## Syntax

``J = imhmax(I,H)``
``J = imhmax(I,H,conn)``

## Description

example

````J = imhmax(I,H)` suppresses regional maxima in the grayscale image `I` by using the H-maxima transform. The H-maxima transform decreases the height of all regional maxima by an amount up to `H`. As a result, the transform fully suppresses regional maxima whose height is less than `H`. Regional maxima are connected pixels with the same intensity value, t, that are surrounded by pixels with an intensity value less than t.```
````J = imhmax(I,H,conn)` additionally specifies the connectivity value used to identify the regional maxima in `I`.```

## Examples

collapse all

Create a sample 10-by-10 image. Add two regional maxima, each consisting of an area of connected pixels surrounded by lower intensity values.

```a = 10*ones(10,10); a(2:4,2:4) = 13; a(6:8,6:8) = 18;```

This image is a grayscale representation of the pixel values. The height of each maximum depends on the surrounding pixel values.

Apply the H-maxima transform that decreases the height of regional maxima by up to 4.

`b = imhmax(a,4);`

This image is a grayscale representation of the transformed image. The transform fully suppresses one of the maxima. The transform partially suppresses the taller maximum, and subtracts 4 from the intensity values of the pixels in that maximum.

You can suppress small regional maxima to identify the brightest peaks in an image.

Read a grayscale image of snowflakes into the workspace and display it.

```I = imread("snowflakes.png"); imshow(I,InitialMagnification=200)```

Find the regional maxima in the image.

`regmax = imregionalmax(I);`

Display a mask of the regional maxima pixels as an overlay on the original image. The regional maxima correspond to shallow intensity fluctuations, rather than the snowflakes.

```overlay = imoverlay(I,regmax,"green"); imshow(overlay,InitialMagnification=200)```

Apply the H-maxima transform to remove the shallow intensity peaks. Display the filtered image.

```h = 75; B = imhmax(I,h); imshow(B,InitialMagnification=200)```

Find the regional maxima of the filtered image. Display a mask of the maxima as an overlay on the original image.

```regmaxfilt = imregionalmax(B); overlayfilt = imoverlay(I,regmaxfilt,"green"); imshow(overlayfilt,InitialMagnification=200)```

Note that you can alternatively use the `imextendedmax` function to apply the H-maxima transform and calculate the regional maxima in one step.

## Input Arguments

collapse all

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

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

H-maxima transform, specified as a nonnegative scalar.

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

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`

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

Current pixel is shown in gray.

`8`

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.

Current pixel is shown in gray.

Three-Dimensional Connectivities

`6`

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

Current pixel is shown in gray.

`18`

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

Current pixel is center of cube.

`26`

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

Current pixel is center of cube.

For higher dimensions, `imhmax` 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 `0`s and `1`s. 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

Transformed image, returned as a numeric array of the same size and class as `I`.

## References

[1] Soille, P. Morphological Image Analysis: Principles and Applications. Springer-Verlag, 1999, pp. 170-171.

## Version History

Introduced before R2006a