【matlab_郭彦甫课程答案】

@matlab郭彦甫第九课p5,写一个程序将大米图片变成二进制图片,不使用im2bw();尝试不同的阈值。

PRACTICE: write a program to convert the image rice.png into a binary image using a threshold

Do not use im2bw();不使用内置函数im2bw()
Try different threshold values to see if you program works%已经解决

clear all, close all
I = imread('rice.png');
BW = imbinarize(I);%将灰阶图像转换imbinarize 使用 Otsu 的方法,该方法选择阈值以最小化阈值化的黑白像素的类内方差

level = 0.3   %(user-defined level,可自定义)
[a,b]=size(I)
 for i=1:a
    for j= 1:b
        if BW(i,j)> level;
            BW(i,j)=1;
        else
            BW(i,j)= 0;
        end
    end
end
subplot(1,2,1);imshow(I);
subplot(1,2,2);imshow(BW);

以上百分号后为注释内容,本人使用matlab2021b可以直接跑,其他版本matlab可以尝试copy以上代码跑一跑。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小熊呀~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值