function guidftfiltreoriente
%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' ,-90,'Max',90, ...
'Position', [180 10 100 20],...
'Value', -20,...
'SliderStep',[0.01 0.1], ...
'callback',{@filtre,'filtrebas'});
uicontrol( 'style','slider',...
'string','filtrehaut',...
'Min' ,-90,'Max',90, ...
'Position', [320 10 100 20],...
'Value', 20,...
'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);
% for m = 1 : M
% for n = 1 : N
% f(m,n)=exp(1i*2*pi*(M*m/2+N*n/2))*f(m,n);
% end
% end
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)*exp(1i*pi*((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');
f = getappdata(1,'f');
filtrebas = getappdata(1,'filtrebas');
filtrehaut = getappdata(1,'filtrehaut');
[M N]=size(f);
centreligne = ceil(M/2);
centrecolonne = ceil(N/2);
% phasebas = filtrebas
% phasehaut= filtrehaut
filtre=zeros(M,N);
for i = 1 : M
for j = 1 : N
Dl= i-centreligne;
Dc= j-centrecolonne;
phase = atan(Dc/Dl)*180/pi;
if ( (phase<=filtrehaut ) && (phase>=filtrebas) )
filtre(i,j) = 0;
else
filtre(i,j) = 1;
end
end
end
%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));
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)*exp(-1i*pi*((m+1)+(n+1))) * e1 * e2)/(M*N);
end
end
end
set( text(4), '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(4))
imshow(uint8(fr));
end
end
Copyright © 2010-2014, tous droits réservés, contact : operationpixel@free.fr