版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、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(
3、K);title('線性變換圖像0.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),
4、imshow(H);title('對(duì)數(shù)變換圖像');axis(50,250,50,200);grid 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)域平均法
5、抑制噪聲程序:I=imread('xian.bmp');subplot(231)imshow(I)title('原始圖像')I=rgb2gray(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; %
6、進(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),imshow(k1);title('3*3模板平滑濾波');subplot(234),imshow(k2);title('5*5模板平滑濾波');subplot(235),imshow(k3);title('7*7模板平滑濾波');subplot(236)
7、,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);title('添加椒鹽噪聲圖像');k1=medfilt2(J); %進(jìn)行3*3模板中值濾波k2=medfilt2(J,5,5); %進(jìn)行5*5模板
8、中值濾波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模板中值濾波');7.用Sobel算子和拉普拉斯對(duì)圖像銳化:I=imrea
9、d('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,
10、2,3),imshow(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.梯度算子檢測(cè)邊緣用MATLAB實(shí)現(xiàn)如下:I=imread('x
11、ian.bmp');subplot(2,3,1);imshow(I);title('原始圖像');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; %顯示坐標(biāo)系I2=edge(I1,'roberts');figure;subplot(2,3,3);imshow(I2);title('rober
12、ts算子分割結(jié)果');axis(50,250,50,200);grid on; %顯示網(wǎng)格線axis on; %顯示坐標(biāo)系I3=edge(I1,'sobel');subplot(2,3,4);imshow(I3);title('sobel算子分割結(jié)果');axis(50,250,50,200);grid on; %顯示網(wǎng)格線axis on; %顯示坐標(biāo)系I4=edge(I1,'Prewitt');subplot(2,3,5);imshow(I4);title('Prewitt算子分割結(jié)果');axis(50,250,50,
13、200);grid on; %顯示網(wǎng)格線axis on; %顯示坐標(biāo)系9.LOG算子檢測(cè)邊緣用MATLAB程序?qū)崿F(xiàn)如下:I=imread('xian.bmp');subplot(2,2,1);imshow(I);title('原始圖像');I1=rgb2gray(I);subplot(2,2,2);imshow(I1);title('灰度圖像');I2=edge(I1,'log');subplot(2,2,3);imshow(I2);title('log算子分割結(jié)果');10.Canny算子檢測(cè)邊緣用MATLAB程
14、序?qū)崿F(xiàn)如下:I=imread('xian.bmp');subplot(2,2,1);imshow(I);title('原始圖像')I1=rgb2gray(I);subplot(2,2,2);imshow(I1);title('灰度圖像');I2=edge(I1,'canny');subplot(2,2,3);imshow(I2);title('canny算子分割結(jié)果');11.邊界跟蹤(bwtraceboundary函數(shù))clcclear allI=imread('xian.bmp');figure
15、imshow(I);title('原始圖像');I1=rgb2gray(I); %將彩色圖像轉(zhuǎn)化灰度圖像threshold=graythresh(I1); %計(jì)算將灰度圖像轉(zhuǎn)化為二值圖像所需的門(mén)限BW=im2bw(I1, threshold); %將灰度圖像轉(zhuǎn)化為二值圖像figureimshow(BW);title('二值圖像');dim=size(BW);col=round(dim(2)/2)-90; %計(jì)算起始點(diǎn)列坐標(biāo)row=find(BW(:,col),1); %計(jì)算起始點(diǎn)行坐標(biāo)connectivity=8;num_points=180;contour=b
16、wtraceboundary(BW,row,col,'N',connectivity,num_points);%提取邊界figureimshow(I1);hold on;plot(contour(:,2),contour(:,1), 'g','LineWidth' ,2);title('邊界跟蹤圖像');12.Hough變換I= imread('xian.bmp');rotI=rgb2gray(I);subplot(2,2,1);imshow(rotI);title('灰度圖像');axis(50,
17、250,50,200);grid on; axis on;BW=edge(rotI,'prewitt');subplot(2,2,2);imshow(BW);title('prewitt算子邊緣檢測(cè)后圖像');axis(50,250,50,200);grid on; axis on;H,T,R=hough(BW);subplot(2,2,3);imshow(H,'XData',T,'YData',R,'InitialMagnification','fit');title('霍夫變換圖'
18、;);xlabel('theta'),ylabel('rho');axis on , axis normal, hold on;P=houghpeaks(H,5,'threshold',ceil(0.3*max(H(:);x=T(P(:,2);y=R(P(:,1);plot(x,y,'s','color','white');lines=houghlines(BW,T,R,P,'FillGap',5,'MinLength',7);subplot(2,2,4);,imsh
19、ow(rotI);title('霍夫變換圖像檢測(cè)');axis(50,250,50,200);grid on; axis on;hold on;max_len=0;for k=1:length(lines)xy=lines(k).point1;lines(k).point2;plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','ye
20、llow');plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');len=norm(lines(k).point1-lines(k).point2);if(len>max_len)max_len=len;xy_long=xy;endendplot(xy_long(:,1),xy_long(:,2),'LineWidth',2,'Color','cyan');13.直方圖閾值法用MATLAB實(shí)現(xiàn)直方圖閾值法:I=im
21、read('xian.bmp');I1=rgb2gray(I);figure;subplot(2,2,1);imshow(I1);title('灰度圖像')axis(50,250,50,200);grid on; %顯示網(wǎng)格線axis on; %顯示坐標(biāo)系m,n=size(I1); %測(cè)量圖像尺寸參數(shù)GP=zeros(1,256); %預(yù)創(chuàng)建存放灰度出現(xiàn)概率的向量for k=0:255 GP(k+1)=length(find(I1=k)/(m*n); %計(jì)算每級(jí)灰度出現(xiàn)的概率,將其存入GP中相應(yīng)位置endsubplot(2,2,2),bar(0:255,GP,&
22、#39;g') %繪制直方圖title('灰度直方圖')xlabel('灰度值')ylabel('出現(xiàn)概率')I2=im2bw(I,150/255); subplot(2,2,3),imshow(I2);title('閾值150的分割圖像')axis(50,250,50,200);grid on; %顯示網(wǎng)格線axis on; %顯示坐標(biāo)系I3=im2bw(I,200/255); %subplot(2,2,4),imshow(I3);title('閾值200的分割圖像')axis(50,250,50,200
23、);grid on; %顯示網(wǎng)格線axis on; %顯示坐標(biāo)系14. 自動(dòng)閾值法:Otsu法用MATLAB實(shí)現(xiàn)Otsu算法:clcclear allI=imread('xian.bmp');subplot(1,2,1),imshow(I);title('原始圖像')axis(50,250,50,200);grid on; %顯示網(wǎng)格線axis on; %顯示坐標(biāo)系level=graythresh(I); %確定灰度閾值BW=im2bw(I,level);subplot(1,2,2),imshow(BW);title('Otsu法閾值分割圖像')
24、axis(50,250,50,200);grid on; %顯示網(wǎng)格線axis on; %顯示坐標(biāo)系15.膨脹操作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)系se=strel('disk',1); %生成圓形結(jié)構(gòu)元素I2=imdilate(I1,se); %用生成的結(jié)構(gòu)元素對(duì)圖像進(jìn)行膨脹subplot(1,2,2);imshow(
25、I2);title('膨脹后圖像');axis(50,250,50,200);grid on; %顯示網(wǎng)格線axis on; %顯示坐標(biāo)系16.腐蝕操作MATLAB實(shí)現(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)系se=strel('disk',1); %生成圓形結(jié)構(gòu)元素I2=imerode(I1,se);
26、%用生成的結(jié)構(gòu)元素對(duì)圖像進(jìn)行腐蝕subplot(1,2,2);imshow(I2);title('腐蝕后圖像');axis(50,250,50,200);grid on; %顯示網(wǎng)格線axis on; %顯示坐標(biāo)系17.開(kāi)啟和閉合操作用MATLAB實(shí)現(xiàn)開(kāi)啟和閉合操作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),imshow(I1);t
27、itle('灰度圖像');axis(50,250,50,200);axis on; %顯示坐標(biāo)系 se=strel('disk',1); %采用半徑為1的圓作為結(jié)構(gòu)元素I2=imopen(I1,se); %開(kāi)啟操作I3=imclose(I1,se); %閉合操作subplot(2,2,3),imshow(I2);title('開(kāi)啟運(yùn)算后圖像');axis(50,250,50,200);axis on; %顯示坐標(biāo)系subplot(2,2,4),imshow(I3);title('閉合運(yùn)算后圖像');axis(50,250,50,2
28、00);axis on; %顯示坐標(biāo)系18.開(kāi)啟和閉合組合操作I=imread('xian.bmp'); %載入圖像subplot(3,2,1),imshow(I);title('原始圖像');axis(50,250,50,200);axis on; %顯示坐標(biāo)系I1=rgb2gray(I);subplot(3,2,2),imshow(I1);title('灰度圖像');axis(50,250,50,200);axis on; %顯示坐標(biāo)系 se=strel('disk',1); I2=imopen(I1,se); %開(kāi)啟操作I3
29、=imclose(I1,se); %閉合操作subplot(3,2,3),imshow(I2);title('開(kāi)啟運(yùn)算后圖像');axis(50,250,50,200);axis on; %顯示坐標(biāo)系subplot(3,2,4),imshow(I3);title('閉合運(yùn)算后圖像');axis(50,250,50,200);axis on; %顯示坐標(biāo)系se=strel('disk',1);I4=imopen(I1,se);I5=imclose(I4,se);subplot(3,2,5),imshow(I5); %開(kāi)閉運(yùn)算圖像title('開(kāi)閉運(yùn)算圖像');axis(50,250,50,200);axis on; %顯示坐標(biāo)系I6=imclose(I1,se);I7=imopen(I6,se);subplot(3,2,6),imshow(I7); %閉
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 教學(xué)設(shè)計(jì)方案作業(yè)
- XX公司天花吊頂施工合作合同
- 個(gè)人貸款合同范文及格式
- 個(gè)人保證擔(dān)保借款合同書(shū)正式版
- 臨街門(mén)面租賃合同標(biāo)準(zhǔn)版
- 中鐵物資商城物流配送合同新范本
- 個(gè)人住房抵押借款合同模板
- 產(chǎn)品生產(chǎn)裝配標(biāo)準(zhǔn)化合同
- 采購(gòu)預(yù)付款合同范本
- 臨建勞務(wù)合同范本
- 廉潔應(yīng)征承諾書(shū)
- 醫(yī)院定崗定編
- 計(jì)算機(jī)網(wǎng)絡(luò)畢業(yè)論文3000字
- 2023年大學(xué)物理化學(xué)實(shí)驗(yàn)報(bào)告化學(xué)電池溫度系數(shù)的測(cè)定
- 農(nóng)村公共基礎(chǔ)知識(shí)
- 腦出血的護(hù)理課件腦出血護(hù)理查房PPT
- 煤礦機(jī)電運(yùn)輸安全培訓(xùn)課件
- 扣繳個(gè)人所得稅報(bào)告表-(Excel版)
- Unit+4+History+and+Traditions單元整體教學(xué)設(shè)計(jì)課件 高中英語(yǔ)人教版(2019)必修第二冊(cè)單元整體教學(xué)設(shè)計(jì)
- 2023年全國(guó)自學(xué)考試00054管理學(xué)原理試題答案
- 六年級(jí)譯林版小學(xué)英語(yǔ)閱讀理解訓(xùn)練經(jīng)典題目(附答案)
評(píng)論
0/150
提交評(píng)論