l'image de fond

Traitements d'Images en Temps frequence

La Transformée en Cosinus Discrète

Equation


dftavec


idftet


dft

La Transformée en Cosinus Discrète Inverse

Equation


dftavec


idftet


dft

Programme

function guidDCT

%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.5 0.4 0.4]);
a(2)=axes('units','normalized',...
    'position',[0.55 0.5 0.4 0.4]);
a(3)=axes('units','normalized',...
    'position',[0.3 0.05 0.4 0.4]);
text(1)=uicontrol(  'style','text',...
            'string','0% ',...
            'Position', [70 30 100 20]);
text(2)=uicontrol(  'style','text',...
            'string','0%',...
            'Position', [440 30 100 20]);
uicontrol(  'style','pushbutton',...
            'string','load',...
            'Position', [10 10 50 20],...
            'callback',@loadimage);
uicontrol(  'style','pushbutton',...
            'string','dct',...
            'Position', [100 10 50 20],...
            'callback',@owndct);
uicontrol(  'style','pushbutton',...
            'string','idct',...
            'Position', [440 10 50 20],...
            'callback',@ownidct);

%parametre initial
setappdata(gcf,'k',8);
setappdata(gcf,'f',1);
setappdata(gcf,'F',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)
    title('image original')
   
end


function owndct(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
                    c1=cos((p*pi*(2*m+1))/(2*M));
                    c2=cos((q*pi*(2*n+1))/(2*N));
                    F(p+1,q+1) =F(p+1,q+1) +  f(m+1,n+1)  * c1 * c2 ;
                end
            end
            if p == 0
                Cp = 1/(M^0.5);
            else
                Cp = (2/M)^0.5;
            end
            if q == 0
                Cq = 1/(N^0.5);
            else
                Cq = (2/N)^0.5;
            end
            F(p+1,q+1) =F(p+1,q+1) * Cp * Cq;
        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(2))
    imshow(uint8(Famplitude));
    title('DCT')
    setappdata(1,'F',F)
         
end


function ownidct(hObj,~)

    F = getappdata(1,'F');
   
    [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
                   if p == 0
                        Cp = 1/(M^0.5);
                    else
                        Cp = (2/M)^0.5;
                    end
                    if q == 0
                        Cq = 1/(N^0.5);
                    else
                        Cq = (2/N)^0.5;
                    end
                    c1=cos(p*pi*((2*m+1)/(2*M)));
                    c2=cos(q*pi*((2*n+1)/(2*N)));
                    fr(m+1,n+1) =fr(m+1,n+1) +  F(p+1,q+1) * Cp * Cq * c1 * c2 ;
                end
            end
        end
        set( text(2), 'String', strcat(num2str((m+1)/M*100),'%'));%  afiche le poucentage d'avancement  de 0 à 1
        pause(0.01)
    end
  %  fr=ceil(real(fr));
    axes(a(3))
    imshow(uint8(fr));
    title('IDCT')
         
end
end


         

Exemple


dct discrete conine transform transformée en cosinus d'une image

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