You are here : matlabImage Processingimbinarize

imbinarize() - Image Processing

BW = imbinarize(I) creates
a binary image from image I by replacing all
values above a globally determined threshold with 1s
and setting all other values to 0s. By default, imbinarize uses
Otsu's method, which chooses the threshold value to minimize the intraclass
variance of the thresholded black and white pixels. imbinarize uses
a 256-bin image histogram to compute Otsu's threshold. To use a different
histogram, see otsuthresh. BW is
the output binary image.exampleBW = imbinarize(I,method) creates
a binary image from image I using the thresholding
method specified by method.BW = imbinarize(I,T) creates
a binary image from image I using the threshold
value T.exampleBW = imbinarize(I,'adaptive',Name,Value) creates
a binary image from image I using name-value
pairs to control aspects of adaptive thresholding.Code Generation support:
Yes.MATLAB Function Block support:


BW = imbinarize(I) exampleBW = imbinarize(I,method) exampleBW = imbinarize(I,T)BW = imbinarize(I,'adaptive',Name,Value) example


Binarize Image Using Global ThresholdOpen This Example
Read grayscale image into the workspace.I = imread('coins.png');
Convert the image into a binary image.BW = imbinarize(I);
Display the original image next to the binary version.figure

Binarize Image Using Locally Adaptive ThresholdingOpen This Example
Read grayscale image into workspace.I = imread('rice.png');
Convert grayscale image to binary image.BW = imbinarize(I, 'adaptive');
Display original image along side binary version.figure

Binarize Images with Darker Foreground Than Background.Open This Example
Read a grayscale image into the workspace and display it.I = imread('printedtext.png');
title('Original Image')

Convert the image to a binary image using adaptive thresholding. Use the ForegroundPolarity parameter to indicate that the foreground is darker than the background.BW = imbinarize(I,'adaptive','ForegroundPolarity','dark','Sensitivity',0.4);
Display the binary version of the image.figure
title('Binary Version of Image')

Output / Return Value


Alternatives / See Also