Skip to content

Instantly share code, notes, and snippets.

@sparksbat
Last active November 21, 2017 02:36
Show Gist options
  • Select an option

  • Save sparksbat/e3f062f5333f397604786f151fa77c7b to your computer and use it in GitHub Desktop.

Select an option

Save sparksbat/e3f062f5333f397604786f151fa77c7b to your computer and use it in GitHub Desktop.
ECE306L Lab 8
A=imread('Fig-1.JPG');
figure('name','Original');
imshow(A);
resz = imresize(A, 0.25);
figure('name','Smaller');
imshow(resz);
resz_resc = imresize(resz, 4);
figure('name','Rescaled');
imshow(resz_resc);
A=imread('Animal-2.JPG');
figure('name','Original');
imshow(A);
% filters(:,:,1) = [0 0 0;0 1 0;0 0 0];%identity
% filters(:,:,2) = 1/9 * [1 1 1;1 1 1;1 1 1];%LPF
% filters(:,:,3) = [1 1 1;1 -8 1;1 1 1];% HPF
% filters(:,:,4) = [-1 -1 -1;-1 8 -1;-1 -1 -1];%spatial
% filters(:,:,5) = [0 0 0;0 0 1;0 0 0];%idk
%Low Pass
lpf(:,:,1) = 1/9 * [1 1 1;1 1 1;1 1 1];%LPF1
lpf(:,:,2) = 1/16 * [1 2 1;2 4 2;1 2 1];%LPF2
for iter = 1:2
figure('name', strcat('lpf-', int2str(iter)));
ifilt = imfilter(A,lpf(:,:,iter));
imshow(ifilt);
end
%High Pass
hpf(:,:,1) = [-1 -1 -1;-1 8 -1;-1 -1 -1];%HPF1
hpf(:,:,2) = [0 -1 0;-1 4 -1;0 -1 0];%LPF2
for iter = 1:2
figure('name', strcat('hpf-', int2str(iter)));
ifilt = imfilter(A,hpf(:,:,iter));
imshow(ifilt);
end
%Spatial
spatial = [-1 -1 -1;-1 8 -1;-1 -1 -1];
figure('name', strcat('Spatial Filtering'));
ifilt = imfilter(A,spatial,'replicate');
imshow(ifilt);
%Laplacian
laplace = [-1 -1 -1;-1 8 -1;-1 -1 -1];
figure('name', strcat('Spatial Filtering - y1'));
y1 = imfilter(A,laplace,'replicate');
imshow(y1);
figure('name', strcat('Spatial Filtering - y2'));
imshow(A+imshow(y1));
f=imread('Animal-2.JPG');
figure, imshow(f);
F=fft2(im2double(f));
S=abs(F);
figure, imshow(S,[]);
Fc=fftshift(F);
S=abs(Fc);
figure, imshow(S,[]);
S2=log(1+abs(Fc));
figure, imshow(S2,[]);
% Average Value
[M,N]=size(f);
S=double(f);
sum=0;
for m=1:M
for n=1:N
sum=S(m,n)+sum;
end
end
A=sum/(M*N);
f=imread('Animal-2.JPG');
imshow(f);
[M,N] = size(f);
F = fft2(im2double(f));
sig = 20;
u = 0:(M-1);
v = 0:(N-1);
idx = find(u>M/2);
u(idx)= u(idx)-M;
idy = find(v>N/2);
v(idy)= v(idy)-N;
[U,V] = meshgrid(v,u);
D0 = sig;
D = sqrt(U.^2+V.^2);
H = exp(-D.^2/(2*D0.^2));
G = F.*H;
g = real(ifft2(G));
figure, imshow(g,[ ]);
f=imread('Animal-2.JPG');
imshow(f);
[M,N] = size(f);
F = fft2(im2double(f));
sig = 20;
u = 0:(M-1);
v = 0:(N-1);
idx = find(u>M/2);
u(idx)= u(idx)-M;
idy = find(v>N/2);
v(idy)= v(idy)-N;
[U,V] = meshgrid(v,u);
D0 = sig;
D = sqrt(U.^2+V.^2);
H = 1- exp(-D.^2/(2*D0.^2));
G = F.*H;
g = real(ifft2(G));
figure, imshow(g,[ ])
g2=double(g);
g3=g2.^4;
figure,imshow(g3,[ ])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment