RGB image to binary image
imageRGB = imread('lenna.jpg');
binary = im2bw(imageRGB,0.4);
imwrite(binary,'test.jpg');
Convert grayscale image to binary image
image = imread('lenna.jpg');
binary = im2bw(image,0.4);
imwrite(binary,'test.jpg');
0.4
It is the threshold. You can change it to a different value, which has different effects.
RGB image:
binary image after conversion:
function
The im2bw() function is a function to convert an RGB image or a binary image into a binary image
note
The use of im2bw may require the installation of additional MATLAB resources. If you haven't installed it before, when you execute it, MATLAB will remind you to install the toolset Image Processing Toolbox
.