22灰度转二值

121 阅读1分钟

close all;clear all;clc;

I=imread('rice.png');

BW1=im2bw(I,0); %将灰度图像转换为二值图像,level值为0

BW2=im2bw(I,0.3); %将灰度图像转换为二值图像,level值为0.3

BW3=im2bw(I,0.5); %将灰度图像转换为二值图像,level值为0.5

BW4=im2bw(I,0.7); %将灰度图像转换为二值图像,level值为0.7

BW5=im2bw(I,1); %将灰度图像转换为二值图像,level值为1

figure;

subplot(231),imshow(I);

subplot(232),imshow(BW1); %显示level=0转换后的二值图像

subplot(233),imshow(BW2); %显示level=0.3转换后的二值图像

subplot(234),imshow(BW3); %显示level=0.5转换后的二值图像

subplot(235),imshow(BW4); %显示level=0.7转换后的二值图像

subplot(236),imshow(BW5); %显示level=1转换后的二值图像