《matlab-圖像分割算法源碼》由會員分享,可在線閱讀,更多相關(guān)《matlab-圖像分割算法源碼(6頁珍藏版)》請?jiān)谘b配圖網(wǎng)上搜索。
1、matlab- 圖像分割算法源碼matlab圖像分割算法源碼1.圖像反轉(zhuǎn)MATLAB程序?qū)崿F(xiàn)如下:I=imread(xian.bmp);J=double(I);J=-J+(256-1);% 圖像反轉(zhuǎn)線性變換H=uint8(J);subplot(1,2,1),imshow(I);subplot(1,2,2),imshow(H);2.灰度線性變換MATLAB程序?qū)崿F(xiàn)如下:I=imread(xian.bmp);subplot(2,2,1),imshow(I);title( 原始圖像 );axis(50,250,50,200);axis on;% 顯示坐標(biāo)系I1=rgb2gray(I);subplot
2、(2,2,2),imshow(I1);title(灰度圖像);axis(50,250,50,200);axis on;% 顯示坐標(biāo)系J=imadjust(I1,0.1 0.5,); %局部拉伸,把0.1 0.5內(nèi)的灰度拉伸為0 1subplot(2,2,3),imshow(J);title(線性變換圖像0.1 0.5);axis(50,250,50,200);grid on;%顯示網(wǎng)格線axis on;% 顯示坐標(biāo)系K=imadjust(I1,0.3 0.7,); %局部拉伸,把0.3 0.7內(nèi)的灰度拉伸為0 1subplot(2,2,4),imshow(K);title(線性變換圖像0.3
3、0.7);axis(50,250,50,200);grid on;%顯示網(wǎng)格線axis on;% 顯示坐標(biāo)系3.非線性變換MATLAB程序?qū)崿F(xiàn)如下:I=imread(xian.bmp);I1=rgb2gray(I);subplot(1,2,1),imshow(I1);title( 灰度圖像 );axis(50,250,50,200);grid on;%顯示網(wǎng)格線axis on;% 顯示坐標(biāo)系J=double(I1);J=40*(log(J+1);H=uint8(J);subplot(1,2,2),imshow(H);title( 對數(shù)變換圖像);axis(50,250,50,200);grid
4、 on;%顯示網(wǎng)格線axis on;% 顯示坐標(biāo)系4.直方圖均衡化MATLAB程序?qū)崿F(xiàn)如下:I=imread(xian.bmp);I=rgb2gray(I);figure;subplot(2,2,1);imshow(I);subplot(2,2,2);imhist(I);I1=histeq(I);figure;subplot(2,2,1);imshow(I1);subplot(2,2,2);imhist(I1);5.線性平滑濾波器用 MATLAB實(shí)現(xiàn)領(lǐng)域平均法抑制噪聲程序:I=imread(xian.bmp);subplot(231)imshow(I)title( 原始圖像 )I=rgb2gr
5、ay(I);I1=imnoise(I,salt & pepper,0.02);subplot(232)imshow(I1)title( 添加椒鹽噪聲的圖像 )k1=filter2(fspecial(average,3),I1)/255;%進(jìn)行 3*3模板平滑濾波k2=filter2(fspecial(average,5),I1)/255;%進(jìn)行 5*5模板平滑濾波k3=filter2(fspecial(average,7),I1)/255;%進(jìn)行 7*7模板平滑濾波k4=filter2(fspecial(average,9),I1)/255;%進(jìn)行 9*9模板平滑濾波subplot(233),
6、imshow(k1);title(3*3模板平滑濾波);subplot(234),imshow(k2);title(5*5模板平滑濾波);subplot(235),imshow(k3);title(7*7模板平滑濾波);subplot(236),imshow(k4);title(9*9模板平滑濾波);6.中值濾波器用 MATLAB實(shí)現(xiàn)中值濾波程序如下:I=imread(xian.bmp);I=rgb2gray(I);J=imnoise(I,salt&pepper,0.02);subplot(231),imshow(I);title(原圖像 );subplot(232),imshow(J);ti
7、tle(添加椒鹽噪聲圖像);k1=medfilt2(J);%進(jìn)行 3*3 模板中值濾波k2=medfilt2(J,5,5);%進(jìn)行 5*5模板中值濾波k3=medfilt2(J,7,7);%進(jìn)行 7*7模板中值濾波k4=medfilt2(J,9,9);%進(jìn)行 9*9模板中值濾波subplot(233),imshow(k1);title(3*3模板中值濾波 );subplot(234),imshow(k2);title(5*5模板中值濾波 );subplot(235),imshow(k3);title(7*7模板中值濾波 );subplot(236),imshow(k4);title(9*9模板
8、中值濾波 );7.用 Sobel 算子和拉普拉斯對圖像銳化:I=imread(xian.bmp);subplot(2,2,1),imshow(I);title(原始圖像);axis(50,250,50,200);grid on;%顯示網(wǎng)格線axis on;% 顯示坐標(biāo)系I1=im2bw(I);subplot(2,2,2),imshow(I1);title(二值圖像);axis(50,250,50,200);grid on;%顯示網(wǎng)格線axis on;% 顯示坐標(biāo)系H=fspecial(sobel);%選擇sobel算子J=filter2(H,I1);% 卷積運(yùn)算subplot(2,2,3),i
9、mshow(J);title(sobel算子銳化圖像 );axis(50,250,50,200);grid on;%顯示網(wǎng)格線axis on;% 顯示坐標(biāo)系h=0 1 0,1 -4 1,0 1 0;%拉普拉斯算子J1=conv2(I1,h,same);% 卷積運(yùn)算subplot(2,2,4),imshow(J1);title( 拉普拉斯算子銳化圖像);axis(50,250,50,200);grid on;%顯示網(wǎng)格線axis on;% 顯示坐標(biāo)系8.梯度算子檢測邊緣用 MATLAB 實(shí)現(xiàn)如下:I=imread(xian.bmp);subplot(2,3,1);imshow(I);title(
10、原始圖像);axis(50,250,50,200);grid on;%顯示網(wǎng)格線axis on;% 顯示坐標(biāo)系I1=im2bw(I);subplot(2,3,2);imshow(I1);title( 二值圖像 );axis(50,250,50,200);grid on;%顯示網(wǎng)格線axis on;I2=edge(I1,roberts);% 顯示坐標(biāo)系figure;subplot(2,3,3);imshow(I2);title(roberts 算子分割結(jié)果 axis(50,250,50,200););grid on;%顯示網(wǎng)格線axis on;I3=edge(I1,sobel);subplot(2,3,4);imshow(I3);% 顯示坐標(biāo)系title(sobel 算子分割結(jié)果 axis(50,250,50,200););grid on;%顯示網(wǎng)格線axis on;% 顯示坐標(biāo)系subplot(2,3,5);imshow(I4);title(Prewitt 算子分割結(jié)果 axis(50,250,50,200););grid on;%顯示網(wǎng)格線axis on;% 顯示坐標(biāo)系9.LOG 算子檢測邊緣用 MATLAB程序?qū)崿F(xiàn)如下:I=imread(xian.bmp);subplot(2,2,1);imshow(I);title( 原始圖像 );I1=rgb2gray(I);