0% found this document useful (0 votes)
528 views

Lab #3 Digital Images: A/D and D/A: Shafaq Tauqir 198292

The document is the lab report for EE330 Digital Signal Processing Lab #3 on digital images. It discusses sampling and reconstruction of digital images. Key points: - Students were introduced to working with digital images in MATLAB, including displaying, sampling, and reconstructing images. - Downsampling the "lighthouse" image by a factor of 2 caused aliasing, most noticeably in high frequency areas like white colors. - Reconstruction using zero-order hold interpolation on rows of a downsampled image with a factor of 3 reduced aliasing compared to the downsampled image. - Linear interpolation using the interp1 MATLAB function is needed to fully reconstruct rows and columns of a downsampled image with minimal alias

Uploaded by

Rabail InKredibl
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
528 views

Lab #3 Digital Images: A/D and D/A: Shafaq Tauqir 198292

The document is the lab report for EE330 Digital Signal Processing Lab #3 on digital images. It discusses sampling and reconstruction of digital images. Key points: - Students were introduced to working with digital images in MATLAB, including displaying, sampling, and reconstructing images. - Downsampling the "lighthouse" image by a factor of 2 caused aliasing, most noticeably in high frequency areas like white colors. - Reconstruction using zero-order hold interpolation on rows of a downsampled image with a factor of 3 reduced aliasing compared to the downsampled image. - Linear interpolation using the interp1 MATLAB function is needed to fully reconstruct rows and columns of a downsampled image with minimal alias

Uploaded by

Rabail InKredibl
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Department of Electrical Engineering

Faculty Member: Dr Shahzad Younis Dated: 27-June-2019

Course/Section: BEE 8 Semester: Spring 2019

EE330-304 Digital Signal Processing


Lab #3 Digital Images: A/D and D/A
PLO4 PLO5 PLO8 PLO9
Name Reg. No Viva / Quiz Analysis Modern Ethics and Individual
/ Lab of data in Tool Safety and Team
Performan Lab Usage Work
ce Report

5 Marks 5 Marks 5 Marks 5 Marks 5 Marks

Shafaq Tauqir 198292

Rabail Khan Lodhi 198887

EE330 Digital Signal Processing Page 1


Lab3: Digital Images: A/D and D/A

Objectives
The objective in this lab is to introduce digital images as a second useful type of signal. We will
show how the A-to-D sampling and the D-to-A reconstruction processes are carried out for digital
images. In particular, we will show a commonly used method of image zooming (reconstruction)
that gives “poor” results.

 Familiarization with digital images.


 Working with images in Matlab.
 Sampling of images
 Familiarization with reconstruction of images

3.1.1 MATLAB Function to Display Images


You can use imshow() to display image type “help imshow” in command window of Matlab to see how
to use imshow

3.1.1 Get Test Images


In order to probe your understanding of image display, do the following simple displays:

(a) Load and display the 326* 426 “lighthouse” image from lighthouse.mat. This image can be find
in the MATLAB files link. The command “ load lighthouse” will put the sampled image into the
array ww/xx. Use whos to check the size of ww after loading.
RESULT:

EE330 Digital Signal Processing Page 2


(b) Use the colon operator to extract the 200th row of the “lighthouse” image, and make a plot of that
rowas a 1-D discrete-time signal.
ww200 = ww(200,:);

Observe that the range of signal values is between 0 and 255. Which values represent white and which
ones black? Can you identify the region where the 200th row crosses the fence?
Black values are represented by 0 and white values are represented by 1.
The region where 200th row crosses the fence is a very high frequency region due rapid change of colors.
RESULT:

EE330 Digital Signal Processing Page 3


3.2 LAB TASKS: Sampling, Aliasing and Reconstruction
3.2 Lab Task 1:
(a) Generate a simple test image in which all of the columns are identical by using the following
outer product: xpix = ones(256,1)*cos(2*pi*(0:255)/16);
Display the image and explain the gray-scale pattern that you see.
PICTURE:

EXPLANATION:
A sinusoid that goes from 1 to 0 then -1 and so on. When its 0, the color is black, when 1, its white.

How wide are the bands in number of pixels?


ANSWER: 256/32= 8.

How can you predict that width from the formula for xpix?
ANSWER: The dimensions of picture are 256*256. And we are keeping frequency 1/16. So there are a
total of 32 bands. Hence 256/32=8.

EE330 Digital Signal Processing Page 4


(b) In the previous part, which data value in xpix is represented by white? which one by black?

3.2.1.1 RESULT:

ANSWER: Positive by white (0 to 1) and negative by black(-1 to 0).

(c) Explain how you would produce an image with bands that are horizontal. Give the formula that
would create a 400*400 image with 5 horizontal black bands separated by white bands. Write the
MATLAB code to make this image and display it.

CODE:
>> ypix=cos(2*pi*(0:399)/80)'*ones(1,400);
>> imshow(ypix)

RESULT:

EE330 Digital Signal Processing Page 5


3.2.2 Lab Task 2:

3.2.3 Sampling of Images


Down-sampling throws away samples, so it will shrink the size of the image. This is what is done by the
following scheme wp = ww(1:p:end,1:p:end); when we are down sampling by a factor of p.

(a) One potential problem with down-sampling is that aliasing might occur. This can be illustrated in a
dramatic fashion with the lighthouse image.
Load the lighthouse.mat file which has the image stored in a variable called ww. When you check
the size of the image, you’ll find that it is not square. Now down sample the lighthouse image by
factor 2.What is the size of the down-sampled image?

RESULT:

Notice the aliasing in the down-sampled image, which is surprising since no new values are
being created by the down-sampling process. Describe how the aliasing appears visually. 9 Which
parts of the image show the aliasing effects most dramatically?
ANSWER:
Highest frequency regions are most affected by aliasing.

3.2.1.1 Down-Sampling
For the lighthouse picture, down sampled by two in the warm-up section:

(a) Describe how the aliasing appears visually. Compare the original to the down sampled image. Which
parts of the image show the aliasing effects most dramatically?

EE330 Digital Signal Processing Page 6


RESULTS:

ORIGINAL DOWN-SAMPLED

EXPLANATION:
Some parts of the downsampled image are distorted due to their frequency domain spectrums
intercepting. The high frequency parts of the original image (white colors) are most affected by aliasing
as they are the ones experiencing the interceptions.

3.2.4 Lab Task 3:

3.2.2 Reconstruction of Images


(a) The simplest interpolation would be reconstruction with a square pulse which produces a “zero-order
hold.” Here is a method that works for a one-dimensional signal (i.e., one row or one column of the
image), assuming that we start with a row vector xr1, and the result is the row vector xr1hold.

xr1 = (-2).ˆ(0:6);
L = length(xr1);
nn = ceil((0.999:1:4*L)/4); %<--Round up to the integer part
xr1hold = xr1(nn);

Plot the vector xr1hold to verify that it is a zero-order hold version derived from xr1.

EE330 Digital Signal Processing Page 7


RESULT:

Explain what values are contained in the indexing vector nn.

RESULT:

1 1 1 1 2 2 2 2 3 3 3 3 4
4 4 4 5 5 5 5 6 6 6 6 7
7 7 7

If xr1holdis treated as an interpolated version of xr1, then what is the interpolation factor?

ANSWER: 4.

Your lab report should include an explanation for this part, but plots are optional—use them if they
simplify the explanation.

ANSWER:

Interpolation factor would be 4 as each element is duplicated to represent 4 values.

(b) Now return to the down-sampled lighthouse image, and process all the rows of xx3 to fill in the
missing points. Use the zero-order hold idea from part (a), but do it for an interpolation factor of 3.

CODE:
clear

EE330 Digital Signal Processing Page 8


clc
load lighthouse;
p=3;
xx3=lighthouse(1:p:end,1:p:end);
n=1:109;
L = length(xx3(n,:));
nn = ceil((0.999:1:3*L)/3); %<--Round up to the integer part
xholdrows = xx3(n,nn);
imshow(xholdrows)

Call the result xholdrows. Display xholdrows as an image, and compare it to the down sampled image
xx3

RESULT:
xholdrows Image:

Downsampled Image:

Q. Compare the size of the images as well as their content.

EE330 Digital Signal Processing Page 9


RESULT:

(c) Now process all the columns of xholdrows to fill in the missing points in each column and call the
result xhold. Compare the result (xhold) to the original image lighthouse. Include your code for parts (b)
and (c) in the lab report.

CODE:
PART B
clear
clc
load lighthouse;
p=3;
xx3=lighthouse(1:p:end,1:p:end);
n=1:109;
L = length(xx3(n,:));
nn = ceil((0.999:1:3*L)/3); %<--Round up to the integer part
xholdrows = xx3(n,nn);
imshow(xholdrows)

PART C
clear
clc
load lighthouse;
p=3;
xx3=lighthouse(1:p:end,1:p:end);
n=1:109;
L = length(xx3(n,:));
nn = ceil((0.999:1:3*L)/3); %<--Round up to the integer part
xholdrows = xx3(n,nn);

m=1:426;
L = 109-(1/3);
nn = ceil((0.999:1:3*L)/3); %<--Round up to the integer part
xhold = xholdrows(nn,m);
imshow(xhold)

EE330 Digital Signal Processing Page 10


RESULTS:

(d) Linear interpolation can be done in MATLAB using the interp1function (that’s “interp-one”).When
unsure about a command, use help. Its default mode is linear interpolation, which is equivalent to using
the ’*linear’ option, but interp1can also do other types of polynomial interpolation.
For the example above, what is the interpolation factor when converting xr1to xr1linear?
ANSWER: The interpolation factor is 10.

(e) In the case of the lighthouse image, you need to carry out a linear interpolation operation on both the
rows and columns of the down-sampled image xx3. This requires two calls to the interp1 function,
because one call will only process all the columns of a matrix. 10 Name the interpolated output image
xxlinear. Include your code for this part in the lab report.

CODE:
load lighthouse
p=3;
xx3=lighthouse(1:p:end,1:p:end);
L=size(xx3);
Lrows=L(1);
Lcolumns=L(2);
for row=1:Lrows
nold=1:Lcolumns;
wp1=xx3(row,:);
nnew=(1/3):(1/3):Lcolumns;
wp1=im2double(wp1);
linear=interp1(nold,wp1,nnew);
xxlinear_rows(row,:) = linear;
end
for column=1:Lcolumns*3
nold=1:Lrows;
wp2=xxlinear_rows(:,column);
nnew=(1/3):(1/3):Lrows-(1/3);
wp2=im2double(wp2);
linear=interp1(nold,wp2,nnew);
xxlinear(:,column)=linear;
end

EE330 Digital Signal Processing Page 11


imshow(xxlinear);

(f) Compare xxlinear to the original image lighthouse. Comment on the visual appearance of the
“reconstructed” image versus the original; point out differences and similarities. Can the reconstruction
(i.e., zooming) process remove the aliasing effects from the down-sampled lighthouse image?

RESULT:
xxlinear: Original:

EXPLANATION:
● There is a big distortion at the edges after the interpolation.
● Also the high frequency areas are heavily distorted too.
● The high frequency region is highly distorted due to aliasing.

(g) Compare the quality of the linear interpolation result to the zero-order hold result. Point out regions
where they differ and try to justify this difference by estimating the local frequency content. In other
words, look for regions of “low-frequency” content and “high-frequency” content and see how the
interpolation quality is dependent on this factor. A couple of questions to think about: Are edges low
frequency or high frequency features? Are the fence posts low frequency or high frequency features? Is
the background a low frequency or high frequency feature?
ANSWER:
● The built in linear interpolation uses a much better algorithm than the zero hold method as the
edges are much better due to the values not stopping suddenly.
● The fence problem is the same in both methods too. The fence problem could not be solved as the
high frequency region is distorted due to aliasing and data there is lost.

EE330 Digital Signal Processing Page 12

You might also like