# Documentation

### This is machine translation

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

# grayconnected

Select contiguous image region with similar gray values

## Syntax

BW = grayconnected(I,row,column)
BW = grayconnected(I,row,column,tolerance)

## Description

example

BW = grayconnected(I,row,column) finds connected regions of similar intensity in the grayscale image I. You specify the intensity value to use as a starting point, the seed pixel, by row and column indices. By default, grayconnected includes connected pixels with values in the range [seedpixel–32,seedpixel+32] for integer-valued images and within the range [seedpixel-0.1,seedpixel+0.1] for floating point images. grayconnected returns a binary mask image, BW, where all of the foreground pixels are 8-connected to the seed pixel at (row, column) by pixels of similar intensity.

example

BW = grayconnected(I,row,column,tolerance) finds connected regions of similar intensity in a grayscale image, where tolerance specifies the range of intensity values to include in the mask, as in [(seedpixel-tolerance),(seedpixel+tolerance)].

## Examples

collapse all

Create small sample image.

I = uint8([20 22 24 23 25 20 100
21 10 12 13 12 30 6
22 11 13 12 13 25 5
23 13 13 13 13 20 5
24 13 13 12 12 13 5
25 26  5 28 29 50 6]);

Create mask image, specifying the seed location by row and column and the tolerance. Since the seed location specifies the pixel with the value 23 and the tolerance is 3 , the range of grayscale values is [20,26].

seedrow = 4
seedrow = 4
seedcol = 1
seedcol = 1
tol = 3
tol = 3
BW = grayconnected(I,seedrow,seedcol,tol)
BW = 6x7 logical array
1   1   1   1   1   1   0
1   0   0   0   0   0   0
1   0   0   0   0   0   0
1   0   0   0   0   0   0
1   0   0   0   0   0   0
1   1   0   0   0   0   0

## Input Arguments

collapse all

Input grayscale image, specified as a real, nonsparse, 2-D matrix.

Example: BW = grayconnected(I,50,40);

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

Row index of seed location, specified as a real, positive, scalar integer.

Example: BW = grayconnected(I,50,40);

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

Column index of seed location, specified as a real, positive, scalar integer.

Example: BW = grayconnected(I,50,40);

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

Range of intensity values to include in the mask, specified as a numeric scalar. The range is defined as [(seedvalue-tolerance),(seedvalue+tolerance)]. By default, grayconnected includes connected pixels with values in the range [seedpixel–32,seedpixel+32] for integer-valued images and within the range [seedpixel-0.1,seedpixel+0.1] for floating point images.

Example: BW = grayconnected(I,50,40,5);

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

## Output Arguments

collapse all

Mask binary image, returned as a logical array where all of the foreground pixels are 8-connected to the seed pixel at (row,column) by pixels of similar intensity.