Monday, 4 April 2016

HW3 solutions and some notes

I haven't double checked the solutions but it looked correct to me. You can comment on the post if you have any comment or question.

CORRECTION
  • In some questions, output of a filtering operation might have negative values. Do not normalize the result in between [0,255] as it is incorrectly done below answers.
  • Histogram equalization is not correct. I found this transfer function [0     0     2     5     7     7     7     7]; You can use my histogram equalization code for checking:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
%% My MATLAB code for finding new equilized histogram
r = [23 12 354 580 215 35 48 8]
pr = r/sum(r)
t= cumsum(pr)*(length(r)-1)
T = round(t)
NewHist = zeros(size(T));
for i=unique(T)
    NewHist(i+1) =  sum(r(T==i));
end
stem(NewHist)


------------









FFT of sobel
[u,v] = meshgrid(-1:0.1:1);

Fuv = -4j*sin(2*pi*u/3)-2j*sin(2*pi*(u/3+v/3))-2j*sin(2*pi*(u/3-v/3));
mesh(Fuv*1j)



FFT of Q7
I = zeros(100);
I(:,20:30) = 1;
F = fftshift(fft2(I));
imshow(abs(F),[0,100]);





Some notes:

Try to sketch (or use MATLAB to visualize) DFT of other geometrical shapes, rectangle, filled rectangle, equilateral hexagon, triangle, filled triangle etc.

You can edit following code to draw FFT of any polygon.
w=300;h=300;

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
%%rectangle
x=[round(w/2);round(w/3);round(w/3);round(w/2)];
y=[round(h/2);round(h/2);round(h/3);round(h/3)];

%draw a vectoral triangle
% fill(x,y,'white','EdgeColor','None'); % Filled with white. No border.
fill(x,y,'black','EdgeColor','white'); % White border. No fill.
% or you can use rectangle('Position',[...positions goes here...],'FaceColor','white','EdgeColor','None');
%zoom
xlim([1,w]); ylim([1,h]);
%paint backgroud to blue
ax = gca;
c = ax.Color;
ax.Color = 'black';
%convert vectoral to raster image
tmp = getframe;
I = im2double(rgb2gray(tmp.cdata));
% For some reason, a brighter frame appears at the verticle edges of the
% axis. So let's trim the image by 10px.
%
I(:, [1:10, size(I,2)-10:size(I,2)]) = 0;
I([1:10, size(I,1)-10:size(I,1)], :) = 0;
imshow(I);
%% FFT
F = fftshift(fft2(I));

imshow(abs(F),[0,100]);


Also, solve the question about aliasing which has been provided after HW assignment. You can find the question in the previous post about midterm hints.

No comments:

Post a Comment