How MATLAB converts RGB or grayscale image to binary image

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.4It is the threshold. You can change it to a different value, which has different effects.
RGB image:
Insert picture description here
binary image after conversion:
Insert picture description here

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.

Guess you like

Origin blog.csdn.net/Bob_ganxin/article/details/108877773