8. matlab圖像處理基礎——邊緣檢測+形態學變換+圖像增強


1、邊緣檢測

① 處理結果 = edge(原始圖像,算子)

  算子:

    Sobel    log

    Roberts      Canny

    Prewitt       zerocross

%% 邊緣檢測
I = imread('cameraman.tif');
J1 = edge(I,'Sobel');
subplot(3,3,1),imshow(I);title('原始圖像');
subplot(3,3,2),imshow(J1);title('Sobel檢測圖像');
J2 = edge(I,'Roberts');
subplot(3,3,3),imshow(J2);title('Roberts檢測圖像');
J3 = edge(I,'Prewitt');
subplot(3,3,4),imshow(J3);title('Prewitt檢測圖像');
J4 = edge(I,'log');
subplot(3,3,5),imshow(J4);title('log檢測圖像');
J5 = edge(I,'Canny');
subplot(3,3,6),imshow(J5);title('Canny檢測圖像');
J6 = edge(I,'zerocross');
subplot(3,3,7),imshow(J6);title('zerocross檢測圖像');

2、形態學變換

(1)圖像腐蝕

  se = strel('disk' ,3);

  resultImage=imerode(originalImage, se);

%% 圖像腐蝕
I = imread('cameraman.tif');
se = strel('disk',3);
J = imerode(I,se);
subplot(1,2,1),imshow(I);
subplot(1,2,2),imshow(J);

(2)膨脹

  se = strel('disk' ,3);

  resultImage=imdilate(originalImage, se);

%% 膨脹
I = imread('cameraman.tif');
se = strel('disk',3);
J = imdilate(I,se);
subplot(1,2,1),imshow(I);
subplot(1,2,2),imshow(J);

(3)開運算

  先腐蝕,后膨脹。

  A被B形態學開運算表示為:A•B

  A被B腐蝕,再用B膨脹結果。

  se = strel('square' ,3);

  resultImage=imopen(originalImage, se);

%% 開運算
I = imread('cameraman.tif');
se = strel('square',3);
J = imopen(I,se);
subplot(1,2,1),imshow(I);
subplot(1,2,2),imshow(J);

(4)閉運算

  先膨脹,后腐蝕。

  A被B形態學閉運算表示為:A•B

  A被B膨脹,再用B腐蝕結果。

  se = strel('square' ,3);

  resultImage=imclose(originalImage, se);

%% 閉運算
I = imread('cameraman.tif');
se = strel('square',3);
J = imclose(I,se);
subplot(1,2,1),imshow(I);
subplot(1,2,2),imshow(J);

3、圖像增強

(1)直方圖

  imhist(原圖像)

%% 直方圖
I = imread('cameraman.tif');
imhist(I);

① 直方圖的均衡化:

  經過均衡化處理的圖像,像素占有更多的灰度級並且分布更均衡。這樣的圖像,具有較高的對比圖。

  處理結果=histeq(原始圖像)

%% 均衡化
I = imread('cameraman.tif');
J = histeq(I);
subplot(2,2,1),imshow(I);
subplot(2,2,2),imshow(J);
subplot(2,2,3),imhist(J);

(2)灰度變換

  結果=imadjust(原始圖像,[原值范圍],[新值范圍])

  原始圖像:自動切換到值在[0,1]

  [原值范圍]:[值1,值2]

  [新值范圍]:[值3,值4]

%% 灰度變換
I = imread('cameraman.tif');
J1 = imadjust(I,[0.3 0.7],[0 1]);
J2 = imadjust(I,[0 1],[1 0]); % 負片
subplot(1,3,1),imshow(I);
subplot(1,3,2),imshow(J1);
subplot(1,3,3),imshow(J2);

(3)灰度對數變換

  增強一幅圖像中較暗部分的細節。

  目標圖像=log(原始圖像);

  代碼:J=log(im2double(I)+1);

I = imread('cameraman.tif');
J = log(im2double(I)+10);
subplot(1,2,1),imshow(I);
subplot(1,2,2),imshow(J,[]);

(4)中值濾波

  處理結果=medfilt2(原始圖像);

%% 中值濾波 
I = imread('cameraman.tif');
J = medfilt2(I);
subplot(1,2,1),imshow(I);
subplot(1,2,2),imshow(J);

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM