MATLAB濾波實驗

來源:互聯網
上載者:User

   clc;
    clear all;
    I=imread('eight.tif');
    % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % %用中值濾波,多維濾波,使用中心為-4,-8的拉普
    % %拉斯濾波器,高斯低通濾波,拉普拉斯濾波器進行濾波處理
    % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    figure;%figure1
    subplot(2,2,1);
    imshow(I);
    title('原始映像');
    J=imnoise(I,'salt & pepper',0.04);%加椒鹽雜訊
    title('加椒鹽雜訊');
    subplot(2,2,2);
    imshow(J);
    K=medfilt2(J,[4,4])%進行中值濾波;
    subplot(2,2,3);
    imshow(K);
    title('進行中值濾波');
    h=ones(3,3)/9;%多維濾波
    w=h;
    g=imfilter(I,w,'conv','replicate')
    subplot(2,2,4);
    imshow(g);
    title('多維濾波');
    %使用中心為-4,-8的拉普拉斯濾波器,
    w4=[1 1 1;
        1 -4 1;
        1 1 1];
    w8=[1 1 1;
        1 -8 1;
        1 1 1];
    f=im2double(I);
    g4=f-imfilter(f,w4,'replicate');
    g8=f-imfilter(f,w8,'replicate');
    imshow(f);
    figure;%figure2
    subplot(1,2,1);
    imshow(g4);
    title('中心為-4的拉普拉斯濾波');
    subplot(1,2,2);
    imshow(g8);
    title('中心為-8的拉普拉斯濾波');
    h3=fspecial('gaussian',[3,3],0.5);%高斯低通濾波
    figure;%figure3
    B4=filter2(h3,I);
    subplot(1,2,1);
    imshow(B4,[ ]);
    title('高斯低通濾波');
    h4=fspecial('laplacian',0);%使用拉普拉斯濾波器
    B5=filter2(h4,I);
    subplot(1,2,2);
    imshow(B5,[ ]);
    title('拉普拉斯濾波器');
    % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % %從空域的角度進行亮度變換
    % %把灰階等級是10-100的變化到10-255
    % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    figure;%figure4
    subplot(2,2,1);
    imshow(I);
    title('原始映像');
    J2=imadjust(I,[],[],0.5);% 增強低灰階級
    subplot(2,2,2);
    imshow(J2);
    title('增強低灰階級');
     J3=imadjust(I,[ ],[ ],2);%增強高灰階級
    subplot(2,2,3);
    imshow(J3);
    title('增強高灰階級');
    a1=100/255;%把灰階等級是10-100的變化到10-255
    a2=255/255;
    a3=10/255;
    J2=imadjust(I,[a3,a1],[a3,a2],[]);
    subplot(2,2,4);
    imshow(J2);
    title('把灰階等級是10-100的變化到10-255');
    % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % %從頻域的角度進行亮度變換
    % %fft2
    % %由於能量主要集中在低頻部分
    % %所以對低頻進行處理可以得到理想的效果
    % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    I=imread('eight.tif');
    up=0.5;%設定處理頻率上限
    down=0.09%%設定處理頻率下限
    figure;%figure5
    subplot(421);
    imshow(I);
    title('原始映像');
    f=double(I);
    subplot(4,2,3);
    imshow(log(abs(f)),[]);
    title('unit8轉化為double');
    g=fft2(f);       
    g=fftshift(g);
    subplot(4,2,5);
    imshow(log(abs(g)),[]);
    title('FFT2變化後的映像');
    [M,N]=size(g);% 轉換資料矩陣
    y1=max(max(abs(g)));%求出最大頻率
    y2=min(min(abs(g)));%%求出最小頻率
    y3=(y1-y2)*up+y2;%設定濾波上限
    y4=(y1-y2)*down+y2;%%設定濾波下限
    for i=1:M
        for j=1:N
    if (abs(g(i,j))<y4)
        g(i,j)=g(i,j)^1.1;%對低頻部分進行灰階增強
    end
       end
    end
    result=ifftshift(g);
     J2=ifft2(result);
     J3=uint8(abs(J2));
     subplot(427);
     imshow(J3,[ ]);
     title('頻域處理後的映像');
    subplot(422)
    imhist(I,64);
    subplot(424)
    imhist(f,64);
    subplot(426)
    imhist(g,64);
    subplot(428)
    imhist(J3,64);

 

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.