天天看點

MatLab 數字圖像處理實驗 圖像分割

實驗(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算子'); 
           
MatLab 數字圖像處理實驗 圖像分割

實驗(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算法');

           
MatLab 數字圖像處理實驗 圖像分割
參考:https://blog.csdn.net/uchihalyn/article/details/104593878

繼續閱讀