The default luminance threshold of im2bw
is not optimal for most images. If you want to use a threshold appropriate for your image, you must compute the level using graythresh
before calling im2bw
.
In R2016a, the imbinarize
function was introduced. This function computes the luminance threshold and performs binarization in one step. imbinarize
has additional benefits, such as the ability to perform adaptive thresholding when the image has nonuniform shading. For more information, see Image Binarization - New 2016a Functions.
The table shows some typical usages of im2bw
and how to update your code to use imbinarize
instead.
Not Recommended | Recommended |
---|---|
BW = im2bw(I); | BW = imbinarize(I,0.5); |
thresh = graythresh(I);BW = im2bw(I,thresh); | BW = imbinarize(I); |
There are no plans to remove im2bw
at this time.