⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 代码23-4.txt

📁 matlab宝典书籍源码 全部代码 希望大家喜欢
💻 TXT
字号:

f=imread('peppers.png');                         % 读入图像
f=rgb2gray(f);                                   % 转换为灰度图像
f=im2double(f);                                  % 数据类型转换
% 全局阈值
T=0.5*(min(f(:))+max(f(:)));
done=false;
while ~done
    g=f>=T;
    Tn=0.5*(mean(f(g))+mean(f(~g)));
    done=abs(T-Tn)<0.1;
    T=Tn;
end
display('Threshold(T) - Iterative');             % 显示文字
T
r=im2bw(f,T);                               % 图像黑白转换
figure,imshow(f),title('Original Image');         % 显示原始图像
figure,imshow(r);                            % 显示处理后的图像
title('Global Thresholding - Iterative Method'); % 图像标题
Th=graythresh(f);                             % 阈值
display('Threshold(T) - Otsu''s Method');         % 显示文字
Th
s=im2bw(f,Th);                               % 图像黑白转换
figure,imshow(s);                             % 显示处理后的图像
title('Global Thresholding - Otsu''s Method');      % 图像标题
se=strel('disk',10);
ft=imtophat(f,se);
Thr=graythresh(ft);                          % 阈值   
display('Threshold(T) - Local Thresholding');    % 显示文字
Thr
lt=im2bw(ft,Thr);                             % 图像黑白转换
figure,imshow(lt);                            % 显示处理后的图像
title('Local Thresholding');                     % 图像标题

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -