l'image de fond

Traitements d'Images en Temps Frequences

Les filtres: bas, haut et bande.

Méthode

Attention les filtres doivent être inversés si nous utilisons la DFT translatée. En effet les basses fréquences se trouvent au centre et les hautes fréquences aux bords. Il faudra donc faire Filtre = NOT(Filtre).

Programme

function guidftfiltre

%translationfunction guihistogramme
clear all;
close all;
figure(  'name','binarisation',...
            'NumberTitle','off',...
            'MenuBar','none',...
            'color',[0.3137 0.3137 0.5098]);
       
a(1)=axes('units','normalized',...
    'position',[0.05 0.65 0.3 0.3]);
a(2)=axes('units','normalized',...
    'position',[0.05 0.3 0.3 0.3]);
a(3)=axes('units','normalized',...
    'position',[0.55 0.65 0.3 0.3]);
a(4)=axes('units','normalized',...
    'position',[0.55 0.3 0.3 0.3]);

uicontrol(  'style','pushbutton',...
            'string','load',...
            'Position', [10 10 50 20],...
            'callback',@loadimage);
uicontrol(  'style','pushbutton',...
            'string','dft',...
            'Position', [100 10 50 20],...
            'callback',@owndft);

uicontrol(  'style','slider',...
            'string','filtrebas',...
            'Min' ,0,'Max',100, ...
            'Position', [180 10 100 20],...
            'Value', 100,...
            'SliderStep',[0.01 0.1], ...
            'callback',{@filtre,'filtrebas'});
uicontrol(  'style','slider',...
            'string','filtrehaut',...
            'Min' ,0,'Max',100, ...
            'Position', [320 10 100 20],...
            'Value', 0,...
            'SliderStep',[0.01 0.1], ...
            'callback',{@filtre,'filtrehaut'});
uicontrol(  'style','pushbutton',...
            'string','idft',...
            'Position', [440 10 50 20],...
            'callback',@ownidft);
text(1)=uicontrol(  'style','text',...
            'string','0% ',...
            'Position', [70 30 100 20]);
text(2)=uicontrol(  'style','text',...
            'string','fc bas ',...
            'Position', [180 30 100 20]);
text(3)=uicontrol(  'style','text',...
            'string','fc haut ',...
            'Position', [320 30 100 20]);
text(4)=uicontrol(  'style','text',...
            'string','0%',...
            'Position', [440 30 100 20]);
%parametre initial
setappdata(gcf,'k',8);
setappdata(gcf,'f',1);
setappdata(gcf,'filtrebas',100);
setappdata(gcf,'filtrehaut',0);
setappdata(gcf,'F',0);
setappdata(gcf,'filtre',0);
 
function loadimage(~,~)
    % appeler quand appui check box
    [filename, pathname] = uigetfile({'*.jpg;*.tif;*.png;*.gif;*.bmp','All Image Files';...
          '*.*','All Files' },'mytitle',...
          'C:\Work\myfile.jpg')

    f = imread(filename);
    axes(a(1))
    imshow(f)
    if (length(size(f))>2)
        f=f(:,:,1);
    end
    f=uint8(f);
    setappdata(1,'f',f);
    axes(a(1))
    imshow(f)
   
end


function owndft(hObj,~)

    f = getappdata(1,'f');
    [M N]=size(f);
    f=double(f);
    F=double(zeros(M,N));
    for p = 0 : M-1
        for q = 0 : N-1
            for m = 0 : M-1
                for n = 0 : N-1
                    e1=exp((-1i*2*pi*p*m)/M);
                    e2=exp((-1i*2*pi*q*n)/N);
                    F(p+1,q+1) =F(p+1,q+1) +  f(m+1,n+1)    *    e1    *    e2;
                end
            end

        end
        set( text(1), 'String', strcat(num2str((p+1)/M*100),'%'));% afiche le poucentage d'avancement  de 0 à 1
        pause(0.01)
    end
   
    Famplitude=log2(1+abs(F));% affichage en logarithmique
    Famplitude=(Famplitude-min(min(Famplitude)))*255/(max(max(Famplitude))-min(min(Famplitude)));% affichage en logarithmique
    axes(a(3))
    imshow(uint8(Famplitude));
    setappdata(1,'F',F)
         
end


function filtre(hObj,~,name)

    val = round(get(hObj,'Value'));
    setappdata(1,name,val);
   
    f = getappdata(1,'f');
    filtrebas = getappdata(1,'filtrebas');
    filtrehaut = getappdata(1,'filtrehaut');

    [M N]=size(f);
    centreligne = ceil(M/2);
    centrecolonne = ceil(N/2);
    modulemax = ((1-centreligne)^2+(1-centrecolonne)^2)^0.5;
    filtrebas= filtrebas*modulemax/100;
    filtrehaut= filtrehaut*modulemax/100;
    filtre=zeros(M,N);
    for i = 1 : M
        for j = 1 : N
            module = ((i - centreligne)^2 + (j - centrecolonne)^2)^0.5;
            if ( (module<=filtrebas ) && (module>=filtrehaut ) )
                filtre(i,j) = 1;
            else
                filtre(i,j) = 0;
            end
        end
    end
   
    setappdata(1,'filtre',filtre)
    axes(a(2))
    imshow(filtre*255)
end
function ownidft(hObj,~)

    F = getappdata(1,'F');
    filtre = getappdata(1,'filtre');
    %application du filtre
    F=F.*filtre;
    Famplitude=log2(1+abs(F));% affichage en logarithmique
    Famplitude=(Famplitude-min(min(Famplitude)))*255/(max(max(Famplitude))-min(min(Famplitude)));% affichage en logarithmique
    axes(a(3))
    imshow(uint8(Famplitude));
   
    [M N]=size(F);
    fr=double(zeros(M,N));
    for m = 0 : M-1
        for n = 0 : N-1
            for p = 0 : M-1
                for q = 0 : N-1
                    e1=exp((1i*2*pi*p*m)/M);
                    e2=exp((1i*2*pi*q*n)/N);
                    fr(m+1,n+1) =fr(m+1,n+1) + (F(p+1,q+1)    *    e1    *    e2)/(M*N);
                end
            end
           set( text(4), 'String', strcat(num2str((m+1)/M*100),'%'));%  afiche le poucentage d'avancement  de 0 à 1
           pause(0.01)
        end
    end
    fr=ceil(real(fr));
    axes(a(4))
    imshow(uint8(fr));
         
end
end


         

Exemple

Une image filtrée avec un passe bas :
dft filtre passe bas
Une image filtrée avec un passe haut :
dft filtre passe haut
Une image filtrée avec un passe bande :
dft filtre passe bande

Copyright © 2010-2014, tous droits réservés, contact : operationpixel@free.fr