Beruflich Dokumente
Kultur Dokumente
Yuqian Hu
EE224 Section C
Introduction:
This lab shows how the A-to-D sampling and the D-to-A reconstruction processes are carried out
for digital images. Plus, I learned the method of image zooming that gives poor results.
Pre-lab
2.1 Synthesize a Test Image
In this part, we are required to generate a synthetic image from a mathematical formula.
(a) First I need to generate a 256256 test image in which all of the columns are identical by
using:
xpix=ones(256,1)*cos(2*pi*(0:255)/16);
(b) When x-pixel equals to 0, the brand is white; when x-pixel equals to 8-9 the brand is black.
So when xpix value is cos(0)=1, the graph displays white, when xpix equals cos(2*pi*(8/16)) = 1 the graph shows black. The sum of black band's length and white bands length is 16, so the
number of black bands is 16.
(c) For this part we need to create a 400400 image with 5 horizontal black bands separated by
white bands. See the code below:
close all;
clear all;
clc;
fignum=1;
xpiy=cos(2*pi*(0:399)/80).'*ones(1,400);
show_img(xpiy);
trusize(fignum);
title('400*400 Test Image');
xlabel('The Pixels on the x-axis');
ylabel('The Pixels on the y-axis');
close all;
clear all;
clc;
load('IPimages.mat')
[endx,endy]=size(shadow);
wp=shadow(1:2:endx,1:2:endy);
show_img(wp);
title('Downsample the shadow');
xlabel('The Pixels on the x-axis');
ylabel('The Pixels on the y-axis');
Comparing the original image and new downsaple image. After zooming the new graph to be the
same as the original images size, I obtained the graphs as above. The shadow part of new image
is less clear than the original shadow part, and the most ambiguous part is a place where shadows
are intensive.
(c) By using frequency domain, I found that the more concentrated the shadows are, the less
clear the shadows are. The spatial frequency is made to be smaller and may be smaller than 2*fo
(maximum frequency), and so the aliased phenomenon happens.
[endx,endy]= size(chainlink);
cl4 = chainlink(1:4:endx,1:4:endy); % set cl4 as the image that down-sampled
at factor at 4
show_img(cl4);
% display cl4 to compare with xhold and yhold's graph
%(b)
[x,y]=size(cl4);
%set x & y equals to the length of cl4's xpix and ypix
n1=1:x; %define our xhold from 1 to x.
p = 4;%interpolar is 4
tti = 1:1/p:x;%location between the n1 indices
xholdrows = interp1(n1,cl4,tti,'nearest'); % use interp1 function to get our
xhold graph.
show_img(xholdrows); %display xhold
%(c)
[x1,y1] = size(xholdrows); % begin to handle yhold, set x1 & y1 equals to the
length of xhold'sxpix and ypix
n2=1:y1;%define our yhold from 1 to y1
p=4;%interpolar is 4
ttj=1:1/p:y1;%location between the n2 indices
yholdcols = interp1(n2,xholdrows',ttj,'nearest');% use interp1 function to
get our yhold graph.
show_img(yholdcols');%display yhold
The horizontal part(x-pix) stays the same but y-pix changed, and the xpix size is 170 which is the
same as the one of c14.
Comparing the final image yhold to cl4, we can see these two graphs have the same clarity.
Then I compared the yhold with original chainlink.
Our original Chainlink image has the same size as yhold, but much more clear than it.
(d) n1 = 0:6; % Define a function with integer values from 0 to 6
xr1 = 8*cos(pi*n1/3); % Define the function to be interpolated
p = 8; % set the interpolation factor
tti = 0:1/p:6; %-- locations between the n1 indices
xr1linear = interp1(n1,xr1,tti,'linear'); %-- function is INTERP-ONE
subplot(211);stem(n1,xr1); %plot original and new graph in same page
subplot(212);stem(tti,xr1linear);
From this graph we can find that different to nearest one, in linear reconstruction, our
new graph(xr1linear) take the near value for x[n], and treat them like linear equation, and
full the empty part by that linear equation.
(e) and (f)
Similarly as what we did in part b and c, we need to reconstruct our cl4 to original size,
by using interp1(with linear).
loadIPimages;
[endx,endy]= size(chainlink);
cl4 = chainlink(1:4:endx,1:4:endy);
[x,y]=size(cl4);
show_img(cl4);
xlabel('xpixel');
ylabel('ylabel');
title('cl4');
n1=1:x;
p = 4;
tti = 1:1/p:x;
xholdrows = interp1(n1,cl4,tti,'linear');
show_img(xholdrows);
xlabel('xpixel');
ylabel('ylabel');
title('xholdrows');
[x1,y1]=size(xholdrows);
n2=1:y1;
ttj=1:1/p:y1;
yholdcols = interp1(n2,xholdrows',ttj,'linear');
xxlinear=yholdcols'
show_img(xxlinear);
xlabel('xpixel');
ylabel('ylabel');
title('yholdcols');
This code is almost the same with what we did in part 2 and 3, the only difference is here we use
linear for interp1, and we need to take the transpose of yholdcols to get xxlinear.
Its still less clear than the original graph, Then also compare the xxlinear, with
yholdcols(nearest)
(g) Its easy to see that linear way will result in a better graph view than nearest way.
The reason I thought should be, since the image was built by a bunch of sine-wave, if we simply
choose some max, min value, and fill their near position with theirs value, the output image will
change a lot, but if we choose the linear way, the output still different with original graph, but
will be better than nearest way, we replace sine-wave by many triangles connect the peak to zero,
and zero to min.
So the linear way is much better than the nearest way when we reconstruct images.