Image Processing Toolbox | ![]() ![]() |
Convert an image to a binary image, based on threshold
Syntax
BW = im2bw(I,level) BW = im2bw(X,map,level) BW = im2bw(RGB,level)
Description
im2bw
produces binary images from indexed, intensity, or RGB images. To do this, it converts the input image to grayscale format (if it is not already an intensity image), and then converts this grayscale image to binary by thresholding. The output binary image BW
has values of 0 (black) for all pixels in the input image with luminance less than level
and 1 (white) for all other pixels. (Note that you specify level
in the range [0,1], regardless of the class of the input image.)
BW = im2bw(I,level)
converts the intensity image I
to black and white.
BW = im2bw(X,map,level)
converts the indexed image X
with colormap map
to black and white.
BW = im2bw(RGB,level)
converts the RGB image RGB
to black and white.
Class Support
The input image can be of class uint8
, uint16
, or double
. The output image BW
is of class uint8
.
Example
load trees BW = im2bw(X,map,0.4); imshow(X,map) figure, imshow(BW)
See Also
![]() | ifftn | im2col | ![]() |