实验(1)以chair.jpg图像为例,分别采用sobel、prewitt、roberts和log对该图像及其加上噪声后的图像进行边缘检测。
close all
clear all
I=imread('D:/chair.jpg');
I_noise=imnoise(I,'gaussian',0.06);
bw1=edge(I_noise,'sobel');
bw2=edge(I_noise,'prewitt');
bw3=edge(I_noise,'roberts');
bw4=edge(I_noise,'log',[],4);
subplot(2,3,1);imshow(I);xlabel('原图');
subplot(2,3,2);imshow(I_noise,[]);xlabel('加入高斯噪声后的图像');
subplot(2,3,3);imshow(bw1);xlabel('Sober算子');
subplot(2,3,4);imshow(bw2);xlabel('Prewitt算子');
subplot(2,3,5);imshow(bw3);xlabel('Robrtts算子');
subplot(2,3,5);imshow(bw4);xlabel('LoG算子');
实验(2)以cell.jpg图像为例,分别迭代式阈值选择法和最大类间方差阈值选择法对该图像进行分割。
clc
close all
clear all
I=imread('D:/cell.jpg');
I=im2double(I);
[width.heoght]=size(I)
T1=graythresh(I);
BW1=im2bw(I,T1);
f=double(I);
T=(min(f(:))+max(f(:)))/2;
done=false;
i=0;
while~done
r1=find(f<=T);
r2=find(f>T);
Tnew=(mean(f(r1))+mean(f(r2)))/2
done=abs(Tnew-T)<1
T=Tnew;
i=i+1;
end
f(r1)=0;
f(r2)=1;
subplot(1,3,1);imshow(I);xlabel('原图');
subplot(1,3,2);imshow(f);xlabel('迭代式阈值选择法');
subplot(1,3,3);imshow(BW1);xlabel('Otsu算法');
参考:https://blog.csdn.net/uchihalyn/article/details/104593878