I have a grayscale image that only has the values 60
and 117
. How can I convert the image to only black
and white
without graylevels?
I tried the matlab
function gray2ind
, but didn't get the expected output.
Thanks.
I have a grayscale image that only has the values 60
and 117
. How can I convert the image to only black
and white
without graylevels?
I tried the matlab
function gray2ind
, but didn't get the expected output.
Thanks.
Try im2bw(img, level)
with level = 0.5
.
This is a matlab function that takes a grayscale image img
, applies a threshold of level
(a value between [0,1]) and returns a black and white image.
This function is part of the Image Processing Toolbox. Your case is simple enough that you could also try something like:
bwImg = false(size(img));
bwImg(img == 117) = true;
I edited the above to set values equal to false/true to more closely mimic Matlab's im2bw()
which returns a matrix of logical
values rather than ints
.
2nd Edit: Modified the code block to reflect improvements suggested by @Amro