clear all; close all;
[filename, pathname] = uigetfile({'*.jpg;*.tif;*.png;*.gif;*.bmp','All Image Files';...
'*.*','All Files' },'mytitle',...
'C:\Work\myfile.jpg')
f = imread(filename);
% image sur un plan
if (length(size(f))>2)
f=f(:,:,1);% passage de 3 dimensions à 1 ( couleur->niveau de gris)
end
% nombre de bit
k=8;
ordre=1; % ordre du filtre.
gamma = 0.7;
%rectification de la taille de l'image pour avoir matrice carré de taille
%d'une puissance de 2
[M N]=size(f);
tailleligne = log2(M);
taillecolonne = log2(N);
dimension = floor(min(tailleligne,taillecolonne))
f1=f(1:2^dimension,1:2^dimension);
%taille de la matrice
[M N]=size(f1);
f1=double(f1);
if ordre == 1
for i = -ordre : ordre
for j = -ordre : ordre
distance = ( i^2 + j^2 )^0.5;
w(i+ordre+1,j+ordre+1)=exp(-distance^2/(2*gamma)^2);
end
end
moyenne = sum(sum(w));
w=w./moyenne;
elseif ordre == 2
for i = -ordre : ordre
for j = -ordre : ordre
distance = ( i^2 + j^2 )^0.5;
w(i+ordre+1,j+ordre+1)=exp(-distance^2/(2*gamma)^2);
end
end
w=w./moyenne;
end
%effet de bord
%decomposition
for d = 1 : dimension
if d == 1
f=f1;
else
eval(['f=F',num2str(d),';']);
end
[M N]=size(f);
f=double(f);
F=double(zeros(floor(M/2),floor(N/2)));
for i= 1: ordre
f=[f(1,1),f(1,:),f(1,end) ; f(:,1),f,f(:,end) ; f(end,1),f(end,:),f(end,end)];
end
%reduction
for p = ordre : floor(M/2)
for q = ordre : floor(N/2)
for m = -ordre : ordre
for n = -ordre : ordre
F(p-ordre+1,q-ordre+1) =F(p-ordre+1,q-ordre+1) + f(2*p+m,2*q+n)*w(m+ordre+1,n+ordre+1);
end
end
end
end
%expension
Fp=F;
for i= 1: ordre
Fp=[Fp(1,1),Fp(1,:),Fp(1,end) ; Fp(:,1),Fp,Fp(:,end) ; Fp(end,1),Fp(end,:),Fp(end,end)];
end
fr=double(zeros(M+2,N+2));
for m = ordre : M
for n = ordre : N
for p = -ordre : ordre
for q = -ordre : ordre
fr(m-ordre+1,n-ordre+1) =fr(m-ordre+1,n-ordre+1) + Fp(round((m+1-p)/2),round((n+1-q)/2))*w(p+ordre+1,q+ordre+1);
end
end
end
end
L=f(2:end-1,2:end-1)-fr(1:end-2,1:end-2);
eval(['F',num2str(d+1),'=F;']);
eval(['L',num2str(d+1),'=L;']);
end
figure( 'Name','Laplacian Pyramid',...
'NumberTitle','off',...
'color',[0.3137 0.3137 0.5098]);
for d = 1 : dimension+1
eval(['subplot(4,',num2str(ceil((dimension+1)/2)),',',num2str(d),');']);
if d == 1
imshow(uint8(f1));
title('f1');
else
eval(['imshow(uint8(F',num2str(d),'));']);
eval(['title(''F',num2str(d),''');']);
end
if d > 1
eval(['subplot(4,',num2str(ceil((dimension+1)/2)),',',num2str(d+1+ceil((dimension+1))),');']);
eval(['imshow(uint8(L',num2str(d),'+127));']);
eval(['title(''L',num2str(d),''');']);
end
end
% fr = double(zeros(M,N));
% %recomposition
% for m = ordre+1 : M-1
% for n = ordre+1 : N-1
% for p = -ordre : ordre
% for q = -ordre : ordre
% fr(m-ordre+1,n-ordre+1) =fr(m-ordre+1,n-ordre+1) + F(round((m-p)/2),round((n-q)/2))*w(p+ordre+1,q+ordre+1);
% end
% end
% %fr(m-ordre+1,n-ordre+1) =fr(m-ordre+1,n-ordre+1)/moyenne;
% end
% m/M*2% afiche le poucentage d'avancement de 0 à 1
% end
% figure( 'Name','DFT',...
% 'NumberTitle','off',...
% 'color',[0.3137 0.3137 0.5098]);
% subplot(221)
% imshow(uint8(f))
% title('Original');
% subplot(222)
% imshow(uint8(F))
% title('Amplitue DFT affichage logarithme');
% subplot(223)
% imshow(uint8(fr))
% title('IDFT reconstitution');
% subplot(224)
% imshow(uint8(Fp))
% title('Phase DFT affichage logarithme');
clear all; close all;
[filename, pathname] = uigetfile({'*.jpg;*.tif;*.png;*.gif;*.bmp','All Image Files';...
'*.*','All Files' },'mytitle',...
'C:\Work\myfile.jpg')
f = imread(filename);
% image sur un plan
if (length(size(f))>2)
f=f(:,:,1);% passage de 3 dimensions à 1 ( couleur->niveau de gris)
end
% nombre de bit
k=8;
ordre=1; % ordre du filtre.
gamma = 0.7;
%rectification de la taille de l'image pour avoir matrice carré de taille
%d'une puissance de 2
[M N]=size(f);
tailleligne = log2(M);
taillecolonne = log2(N);
dimension = floor(min(tailleligne,taillecolonne));
f1=f(1:2^dimension,1:2^dimension);
%taille de la matrice
[M N]=size(f1);
f1=double(f1);
if ordre == 1
for i = -ordre : ordre
for j = -ordre : ordre
distance = ( i^2 + j^2 )^0.5;
w(i+ordre+1,j+ordre+1)=exp(-distance^2/(2*gamma)^2);
end
end
moyenne = sum(sum(w));
w=w./moyenne;
elseif ordre == 2
for i = -ordre : ordre
for j = -ordre : ordre
distance = ( i^2 + j^2 )^0.5;
w(i+ordre+1,j+ordre+1)=exp(-distance^2/(2*gamma)^2);
end
end
w=w./moyenne;
end
%effet de bord
%decomposition
for d = 1 : dimension
if d == 1
f=f1;
else
eval(['f=F',num2str(d),';']);
end
[M N]=size(f);
f=double(f);
F=double(zeros(floor(M/2),floor(N/2)));
for i= 1: ordre
f=[f(1,1),f(1,:),f(1,end) ; f(:,1),f,f(:,end) ; f(end,1),f(end,:),f(end,end)];
end
%reduction
for p = ordre : floor(M/2)
for q = ordre : floor(N/2)
for m = -ordre : ordre
for n = -ordre : ordre
F(p-ordre+1,q-ordre+1) =F(p-ordre+1,q-ordre+1) + f(2*p+m,2*q+n)*w(m+ordre+1,n+ordre+1);
end
end
end
end
%expension
Fp=F;
for i= 1: ordre
Fp=[Fp(1,1),Fp(1,:),Fp(1,end) ; Fp(:,1),Fp,Fp(:,end) ; Fp(end,1),Fp(end,:),Fp(end,end)];
end
fr=double(zeros(M+2,N+2));
for m = ordre : M
for n = ordre : N
for p = -ordre : ordre
for q = -ordre : ordre
fr(m-ordre+1,n-ordre+1) =fr(m-ordre+1,n-ordre+1) + Fp(round((m+1-p)/2),round((n+1-q)/2))*w(p+ordre+1,q+ordre+1);
end
end
end
end
L=f(2:end-1,2:end-1)-fr(1:end-2,1:end-2);
eval(['F',num2str(d+1),'=F;']);
eval(['L',num2str(d+1),'=L;']);
end
%affichage decomposition
figure( 'Name','Laplacian Pyramid',...
'NumberTitle','off',...
'color',[0.3137 0.3137 0.5098]);
for d = 1 : dimension+1
eval(['subplot(4,',num2str(ceil((dimension+1)/2)),',',num2str(d),');']);
if d == 1
imshow(uint8(f1));
title('f1');
else
eval(['imshow(uint8(F',num2str(d),'));']);
eval(['title(''F',num2str(d),''');']);
end
if d > 1
eval(['subplot(4,',num2str(ceil((dimension+1)/2)),',',num2str(d+1+ceil((dimension+1))),');']);
eval(['imshow(uint8(L',num2str(d),'+127));']);
eval(['title(''L',num2str(d),''');']);
end
end
%recomposition
for d = dimension : -1 : 1
if dimension == d
eval(['F=F',num2str(d+1),';']);
else
eval(['F=fr',num2str(d+1),';']);
end
[M N]=size(F);
F=double(F);
for i= 1: ordre
F=[F(1,1),F(1,:),F(1,end) ; F(:,1),F,F(:,end) ; F(end,1),F(end,:),F(end,end)];
end
fr=double(zeros(M*2,N*2));
for m = ordre : M*2
for n = ordre : N*2
for p = -ordre : ordre
for q = -ordre : ordre
fr(m-ordre+1,n-ordre+1) =fr(m-ordre+1,n-ordre+1) + F(round((m+1-p)/2),round((n+1-q)/2))*w(p+ordre+1,q+ordre+1);
end
end
end
end
eval(['L=L',num2str(d+1),';']);
fr=fr+L;
eval(['fr',num2str(d),'=fr;']);
end
%affichage reconstruction
figure( 'Name','Laplacian Pyramid',...
'NumberTitle','off',...
'color',[0.3137 0.3137 0.5098]);
for d = dimension+1 : -1 : 1
eval(['subplot(4,',num2str(ceil((dimension+1)/2)),',',num2str(dimension+2-d),');']);
if d == dimension+1
eval(['imshow(uint8(F',num2str(d),'));']);
eval(['title(''F',num2str(d),''');']);
else
eval(['imshow(uint8(fr',num2str(d),'));']);
eval(['title(''fr',num2str(d),''');']);
end
if d > 1
eval(['subplot(4,',num2str(ceil((dimension+1)/2)),',',num2str(dimension+2-d+1+ceil((dimension+1))),');']);
eval(['imshow(uint8(L',num2str(d),'+127));']);
eval(['title(''L',num2str(d),''');']);
end
end
Copyright © 2010-2014, tous droits réservés, contact : operationpixel@free.fr