MATLAB如何将RGB或者灰度图像转换为二值图像

RGB图像转二值图像

imageRGB = imread('lenna.jpg');
binary = im2bw(imageRGB,0.4);
imwrite(binary,'test.jpg');

灰度图像转二值图像

image = imread('lenna.jpg');
binary = im2bw(image,0.4);
imwrite(binary,'test.jpg');

0.4是阈值,你可以换成不同的值,有不同的效果。
RGB图像:
在这里插入图片描述
转换后二值图像:
在这里插入图片描述

函数

im2bw()函数是把RGB图像或者二值图像转换成二值图像的函数

注意

使用im2bw可能需要安装MATLAB附加资源。如果你之前没有安装的话,执行时,MATLAB会提醒你安装工具集Image Processing Toolbox

猜你喜欢

转载自blog.csdn.net/Bob_ganxin/article/details/108877773
今日推荐