一、原理
通过设定不同的特征阈值,把图像像素点分为若干类。
二、步骤
①读入原图像eight.tif,并显示图像及其直方图(双峰分布);
②选择直方图中两峰之间的谷对应的灰度作为阈值,对图像进行分割,并显示分割结果。
设图像为 f(x,y) ,阈值为 T ,则
式中,g(x,y) 代表分割后的结果。
三、实验图像
四、框图
五、代码
%------------------------------------------------------------------------
% File name: second
% Last modified Date: 2021年6月10日17点30分
% Author: Jasmine
% Descriptions: 阈值分割
%------------------------------------------------------------------------
%清空工作区
clc,clear,close all;
%读入原图像
eight = imread('D:\eight.tif');
%显示原图像
subplot(2,2,1);imshow(eight);title('原图');
%获取直方图并显示
subplot(2,2,2);imhist(eight);title('原图直方图');
%人工选定阈值进行分割,选择阈值为170
[width,height]=size(eight);
T1=170;
for i=1:width
for j=1:height
if(eight(i,j)<T1)
BW1(i,j)=0;
else
BW1(i,j)=1;
end
end
end
subplot(2,2,3);imshow(BW1),title('阈值分割');
subplot(2,2,4);imhist(BW1);title('阈值分割直方图');