辅导CS 659、MatLab程序语言讲解、辅导MatLab设计、讲解software
- 首页 >> 其他 CS 659 Image Processing
Homework #3
Covering Lectures 7, 8, 9 and Reading Material HW3R
NOTES: Submit only the homework “solution” (do not include these homework questions) in
Microsoft Word format to http://moodle.njit.edu/ before the above deadline. Absolutely, no late
submission is accepted. Write the answers in your own words individually. Any plagiarism will
post a “ZERO” score or cause a “FAIL” grade. The course requires Matlab programming. You can
download the Matlab software from the NJIT website: http://ist.njit.edu/software/download.php.
Submit your answer in a Microsoft Word file. Do not include the questions; just provide the
required answers in the file.
Totally, there are 5 questions. Each question is 20 points. Grading policy checks the correctness
and completion of showing resulting images, Matlab codes, and text responses.
Required reading material: HW3R
Required images: cameraman.tif, coins.png, duck.jpg
3.1 (20 points)
(a) Describe how Hough Transform can detect a straight line. Describe the step-by-step algorithm to
implement Hough Transform for detecting a straight line.
(b) Apply the Hough transform to the following image to detect lines. Show the step-by-step results
of line detection by Hough transform.
0 0 0 0 0 0 0 1
0 0 0 0 0 0 1 0
0 0 0 0 0 1 0 0
0 0 0 0 1 0 0 0
0 0 0 1 0 0 0 0
0 0 1 0 0 0 0 0
0 1 0 0 0 0 0 0
1 0 0 0 0 0 0 0Dr. Frank Shih
(c) Read the following image: cameraman.tif which is 256 ? 256 resolution. Use program to
perform Hough transform. An example of Matlab code: x=imread('cameraman.tif');
hx=hough(x); imshow(mat2gray(hx)*1.5); The multiplication of 1.5 is just to brighten up the
image. The Hough transform function can be written as follows. Show the resulting Hough
transform image.
function res=hough(image)
% HOUGH(IMAGE) creates the Hough transform corresponding to the image IMAGE
edges=edge(image,'canny');
[x,y]=find(edges);
angles=[-90:180]*pi/180;
r=floor(x*cos(angles)+y*sin(angles));
rmax=max(r(find(r>0)));
acc=zeros(rmax+1,270);
for i=1:length(x),
for j=1:270,
if r(i,j)>=0
acc(r(i,j)+1,j)=acc(r(i,j)+1,j)+1;
end;
end;
end;
res=acc;
(d) Find the maximum value of the transform using mx=max(hx(:)), and find the r and theta values
corresponding to the maximum using [r, theta]= find(hx==mx); We can create a small function,
called houghline() as below, to draw lines for us, given their perpendicular distance from the Dr. Frank Shih
origin and the angle of the perpendicular from the x axis. Finally, we can draw the line on top
of the image using: imshow(x); houghline(x, r, theta); Show the resulting line overlapping with
the input image.
function houghline(image,r,theta)
% Draws a line at perpendicular distance R from the upper left corner of the
% current figure, with perpendicular angle THETA to the left vertical axis.
% THETA is assumed to be in degrees.
[x,y]=size(image);
angle=pi*(181-theta)/180;
X=[1:x];
if sin(angle)==0
line([r r],[0,y],'Color','black')
else
line([0,y],[r/sin(angle),(r-y*cos(angle))/sin(angle)],'Color','black')
end;
Answer: (a)(b)(c)(d)
3.2 (20 points)
(a) Read the image “coins.png” and display its histogram plot. Inspect the histogram near the right
of the background pixels by activating data cursor. Choose the threshold value of 120 to
generate a new threshold binary image. Display original image, its histogram plot, and the
threshold binary image.
(b) Read the input image “cameraman.tif” and compute the edges in the image using different edge
detectors like Roberts, Sobel, Prewitt, Log and Canny. Show six images using subplot with title on
each: the original image, Roberts, Sobel, Prewitt, Log and Canny.
Answer: (a)(b)
3.3 (20 points)
(a) Referring to the reading material HW3R, Fig. 4.1, design a binary image of 200 columns by 100
rows, which contains a rectangle whose length = 120 pixels and height = 60 pixels in the center.
Set the rectangle to be white and the background to be black. Use a circular structuring element
whose radius is 9 pixels to perform the following: (Hint: Matlab functions: strel('disk',9,0);
imdilate, imerode, imopen, imclose) (i) Binary dilation (ii) binary erosion (iii) binary opening,
and (iv) binary closing. Show the Matlab source code and the resulting five images: the
rectangular image, the dilated image, the eroded image, the opened image, and the closed
image.
(b) Referring to the reading material HW4R, Fig. 4.2, design a circular structuring element whose
radius is 5 pixels to perform the following operation with the input image “lena_256.bmp”:Dr. Frank Shih
(Hint: Matlab functions: imdilate, imerode, imopen, imclose) (v) Grayscale dilation (vi)
grayscale erosion (vii) grayscale opening, and (viii) grayscale closing. Show the Matlab source
code and the resulting five images: the original Lena image, the dilated image, the eroded
image, the opened image, and the closed image.
(c) Hand calculate the morphological dilation and erosion of f and k as shown below. Use the
upper-left pixel of k as the origin. Note: do not consider the computation to the pixels which are
located outside the boundary of f.
f: k:
1 1
2 -3
Answer: (a)(b)(c)
3.4 (20 points)
(a) Hand calculates the two-step algorithm in Image Representation as follows for the city-block
distance transform on the image data below. Treat the pixels outside the image boundary to be
zeroes. Show the two output data after the first step and the second step.
(b) Repeat the same procedure for the chessboard distance transform. Show the two output data
after the first step and the second step.
bottom- to - top
right - to -left
"( ) min[ '( ), "( ) 1],
Ptop- to - bottom
left - to - right
00011100
11111100
11111111
11111111
11111111
11111110
Answer: (a)(b)
3.5 (20 points)
Use hand calculation to obtain the crack codes for the following binary region by using the crack
following algorithm considering 8-connectedness (so this image contains one object)? Use
hand calculation to obtain the chain codes by using the border following algorithm considering
4-connectedness (so this image contains two objects)? You need to show both (a) crack and (b)
chain codes for the following image. (Note that, using the counter-clockwise approach)
5 3 3 0
1 4 2 7Dr. Frank Shih
0000000
0011110
0111000
0010110
0000000
Answer: (a)(b)
Homework #3
Covering Lectures 7, 8, 9 and Reading Material HW3R
NOTES: Submit only the homework “solution” (do not include these homework questions) in
Microsoft Word format to http://moodle.njit.edu/ before the above deadline. Absolutely, no late
submission is accepted. Write the answers in your own words individually. Any plagiarism will
post a “ZERO” score or cause a “FAIL” grade. The course requires Matlab programming. You can
download the Matlab software from the NJIT website: http://ist.njit.edu/software/download.php.
Submit your answer in a Microsoft Word file. Do not include the questions; just provide the
required answers in the file.
Totally, there are 5 questions. Each question is 20 points. Grading policy checks the correctness
and completion of showing resulting images, Matlab codes, and text responses.
Required reading material: HW3R
Required images: cameraman.tif, coins.png, duck.jpg
3.1 (20 points)
(a) Describe how Hough Transform can detect a straight line. Describe the step-by-step algorithm to
implement Hough Transform for detecting a straight line.
(b) Apply the Hough transform to the following image to detect lines. Show the step-by-step results
of line detection by Hough transform.
0 0 0 0 0 0 0 1
0 0 0 0 0 0 1 0
0 0 0 0 0 1 0 0
0 0 0 0 1 0 0 0
0 0 0 1 0 0 0 0
0 0 1 0 0 0 0 0
0 1 0 0 0 0 0 0
1 0 0 0 0 0 0 0Dr. Frank Shih
(c) Read the following image: cameraman.tif which is 256 ? 256 resolution. Use program to
perform Hough transform. An example of Matlab code: x=imread('cameraman.tif');
hx=hough(x); imshow(mat2gray(hx)*1.5); The multiplication of 1.5 is just to brighten up the
image. The Hough transform function can be written as follows. Show the resulting Hough
transform image.
function res=hough(image)
% HOUGH(IMAGE) creates the Hough transform corresponding to the image IMAGE
edges=edge(image,'canny');
[x,y]=find(edges);
angles=[-90:180]*pi/180;
r=floor(x*cos(angles)+y*sin(angles));
rmax=max(r(find(r>0)));
acc=zeros(rmax+1,270);
for i=1:length(x),
for j=1:270,
if r(i,j)>=0
acc(r(i,j)+1,j)=acc(r(i,j)+1,j)+1;
end;
end;
end;
res=acc;
(d) Find the maximum value of the transform using mx=max(hx(:)), and find the r and theta values
corresponding to the maximum using [r, theta]= find(hx==mx); We can create a small function,
called houghline() as below, to draw lines for us, given their perpendicular distance from the Dr. Frank Shih
origin and the angle of the perpendicular from the x axis. Finally, we can draw the line on top
of the image using: imshow(x); houghline(x, r, theta); Show the resulting line overlapping with
the input image.
function houghline(image,r,theta)
% Draws a line at perpendicular distance R from the upper left corner of the
% current figure, with perpendicular angle THETA to the left vertical axis.
% THETA is assumed to be in degrees.
[x,y]=size(image);
angle=pi*(181-theta)/180;
X=[1:x];
if sin(angle)==0
line([r r],[0,y],'Color','black')
else
line([0,y],[r/sin(angle),(r-y*cos(angle))/sin(angle)],'Color','black')
end;
Answer: (a)(b)(c)(d)
3.2 (20 points)
(a) Read the image “coins.png” and display its histogram plot. Inspect the histogram near the right
of the background pixels by activating data cursor. Choose the threshold value of 120 to
generate a new threshold binary image. Display original image, its histogram plot, and the
threshold binary image.
(b) Read the input image “cameraman.tif” and compute the edges in the image using different edge
detectors like Roberts, Sobel, Prewitt, Log and Canny. Show six images using subplot with title on
each: the original image, Roberts, Sobel, Prewitt, Log and Canny.
Answer: (a)(b)
3.3 (20 points)
(a) Referring to the reading material HW3R, Fig. 4.1, design a binary image of 200 columns by 100
rows, which contains a rectangle whose length = 120 pixels and height = 60 pixels in the center.
Set the rectangle to be white and the background to be black. Use a circular structuring element
whose radius is 9 pixels to perform the following: (Hint: Matlab functions: strel('disk',9,0);
imdilate, imerode, imopen, imclose) (i) Binary dilation (ii) binary erosion (iii) binary opening,
and (iv) binary closing. Show the Matlab source code and the resulting five images: the
rectangular image, the dilated image, the eroded image, the opened image, and the closed
image.
(b) Referring to the reading material HW4R, Fig. 4.2, design a circular structuring element whose
radius is 5 pixels to perform the following operation with the input image “lena_256.bmp”:Dr. Frank Shih
(Hint: Matlab functions: imdilate, imerode, imopen, imclose) (v) Grayscale dilation (vi)
grayscale erosion (vii) grayscale opening, and (viii) grayscale closing. Show the Matlab source
code and the resulting five images: the original Lena image, the dilated image, the eroded
image, the opened image, and the closed image.
(c) Hand calculate the morphological dilation and erosion of f and k as shown below. Use the
upper-left pixel of k as the origin. Note: do not consider the computation to the pixels which are
located outside the boundary of f.
f: k:
1 1
2 -3
Answer: (a)(b)(c)
3.4 (20 points)
(a) Hand calculates the two-step algorithm in Image Representation as follows for the city-block
distance transform on the image data below. Treat the pixels outside the image boundary to be
zeroes. Show the two output data after the first step and the second step.
(b) Repeat the same procedure for the chessboard distance transform. Show the two output data
after the first step and the second step.
bottom- to - top
right - to -left
"( ) min[ '( ), "( ) 1],
Ptop- to - bottom
left - to - right
00011100
11111100
11111111
11111111
11111111
11111110
Answer: (a)(b)
3.5 (20 points)
Use hand calculation to obtain the crack codes for the following binary region by using the crack
following algorithm considering 8-connectedness (so this image contains one object)? Use
hand calculation to obtain the chain codes by using the border following algorithm considering
4-connectedness (so this image contains two objects)? You need to show both (a) crack and (b)
chain codes for the following image. (Note that, using the counter-clockwise approach)
5 3 3 0
1 4 2 7Dr. Frank Shih
0000000
0011110
0111000
0010110
0000000
Answer: (a)(b)