Regional maxima
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
I
— Grayscale imageGrayscale image, specified as a numeric array of any dimension.
Example: I = imread('cameraman.tif');
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| logical
conn
— Pixel connectivity4
| 8
| 6
| 18
| 26
| 3-by-3-by- ... -by-3 matrix of 0
s and
1
sPixel 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:
| |
18-connected | Pixels are connected if their faces or edges touch. The neighborhood of a pixel are the adjacent pixels in:
| |
26-connected | Pixels are connected if their faces, edges, or corners touch. The neighborhood of a pixel are the adjacent pixels in:
|
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
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
BW
— Locations of regional maximaLocations 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
.
Data Types: logical
Usage notes and limitations:
imregionalmax
supports the generation of C
code (requires MATLAB®
Coder™). Note that if you choose the generic MATLAB Host Computer
target platform, imregionalmax
generates code that uses a precompiled,
platform-specific shared library. Use of a shared library preserves performance optimizations
but limits the target platforms for which code can be generated. For more information, see Code Generation Using a Shared Library.
When generating code, the optional second input argument,
conn
, must be a compile-time constant.
Usage notes and limitations:
Inputs must be 2-D, supporting only the 2-D connectivities (4 and 8).
For more information, see Image Processing on a GPU.
conndef
| imextendedmax
| imhmax
| imreconstruct
| imregionalmin
You have a modified version of this example. Do you want to open this example with your edits?