Uploaded by 赵伟光

18

advertisement
数字图像处理及应用 第1次作业
班级: 2019240302
班级学号: 18 姓名: 赵伟光
Part I Exercises
Ex 2.7 Suppose that a flat area with center at
is illuminated by a light source with intensity
distribution
Assume for simplicity that the reflectance of the area is constant and equal to 1.0, and let K = 255.
If the resulting image is digitized with k bits of intensity resolution, and the eye can detect an
abrupt change of four shades of intensity between adjacent pixels, what value of k will cause
visible false contouring?
Answer:
Formula for illumination intensity at points (x,y)
So the light intensity range of this image is [0,255].
Variation in intensity between adjacent pixels:
so m=
=
f=
=64
from
we can know that k=6
Ex 2.12 Develop an algorithm for converting a one-pixel-thick 8-path to a 4-path.
Answer:
If the distance between the two pixels that make up the 8-path is 1, it remains unchanged.
If the distance between the two pixels that make up the 8-path is 2, the conversion is performed
with the help of adjacent pixels.
For example:
If there are 8-path between pixels a(x,y) and b(x+1,y+1),4-path are first established between pixels
a(x,y) and c(x+1,y), and then between pixels c(x+1,y) and b(x+1,y+1); or 4-path are established
between pixels a(x,y) and d(x,y+1), and then between pixels d(x,y+1) and b(x+1,y+1).
Ex 2.15 Consider the image segment shown.
(a) Let
and compute the lengths of the shortest 4-, 8-, and m-path between p and q.
If a particular path does not exist between these two points, explain why.
(b) Repeat for
.
Answer:
(a)
the 4-path:
the 8-path:
the m-path:
(b)
the 4-path: there is no 4-path in p and q
the 8-path:
the m-path:
Ex 2.21 Consider two 8-bit images whose intensity levels span the full range from 0 to 255.
(a) Discuss the limiting effect of repeatedly subtracting image (2) from image (1). Assume that the
result is represented also in eight bits.
(b) Would reversing the order of the images yield a different result?
Answer:
(a) Because the intensity levels of image span the full range from 0 to 255,so the result span the
full range from -255 to 255 inone calculation. We assume that when the intensity less than zero,it
equal to zero. In the process of repeated subtraction, when the value of a pixel becomes zero,
although he still subtracts a positive value the next time, he is zero. There are two cases under
this assumption:
1> When the value of a pixel in (2) is zero, the pixel value of that point in the result is equal to
the pixel value of that point in (1).
2> When the value of a pixel in (2) is not zero, the pixel value of that point in the result is equal
to zero.
(b)
1> When the value of a pixel in (1) is zero, the pixel value of that point in the result is equal to
the pixel value of that point in (2).
2>When the value of a pixel in (1) is not zero, the pixel value of that point in the result is equal
to zero.
Ex 2.22 Image subtraction is used often in industrial applications for detecting missing
components in product assembly. The approach is to store a “golden” image that corresponds to
a correct assembly; this image is then subtracted from incoming images of the same product.
Ideally, the differences would be zero if the new products are assembled correctly. Difference
images for products with missing components would be nonzero in the area where they differ
from the golden image. What conditions do you think have to be met in practice for this method
to work?
Answer:
Let f(x,y) denote any input image acquired during routine operation of the system. The original
image is g(x,y).We give a range [-v,v] that subtracts f(x,y) and g(x,y) pixel by pixel, and if the
interpolation of each point falls within that range, it means that the input image conforms to the
specification, otherwise it means that it does not conform to the specification. And f(x,y) and g(x,y)
of the shooting environment should have the same lighting conditions, otherwise the comparison
results are meaningless, and the noise should also be controlled within a certain range, otherwise
the difference will be mainly determined by noise.
Part II Programming
Example 2.5 For a noisy image which contains Gaussian noise with stand deviation
levels and mean
, observing noise reduction effects by adding (averaging) k noisy images,
and k takes 5, 10, 20, 50, and 100 respectively.
code:
figure;
subplot(3,3,1),imshow(x1),title('origian');
g1=imnoise(x1,'gaussian',0.01);
subplot(3,3,2),imshow(g1),title('gaussian');
w=fspecial('laplacian',0);
g=imfilter(x1,w,'replicate');
g2=x1-g;
subplot(3,3,3),imshow(g2),title('Laplace filtering');
x2=im2double(x1);
for i=1:1:5
d(:,:,i)=imnoise(x2,'gaussian');
end
g3=mean(d,3);
subplot(3,3,4),imshow(g3),title('5 average');
for i=1:1:10
e(:,:,i)=imnoise(x2,'gaussian');
end
g4=mean(e,3);
subplot(3,3,5),imshow(g4),title('10 average');
for i=1:1:20
h(:,:,i)=imnoise(x2,'gaussian');
end
g5=mean(h,3);
subplot(3,3,6),imshow(g5),title('20 average');
for i=1:1:50
gray
j(:,:,i)=imnoise(x2,'gaussian');
end
g6=mean(j,3);
subplot(3,3,7),imshow(g6),title('50 average');
for i=1:1:100
k(:,:,i)=imnoise(x2,'gaussian');
end
g7=mean(k,3);
subplot(3,3,8),imshow(g7),title('100 average');
Example 2.6 Image subtraction for enhancing differences.
1) Firstly, set the least-significant bit of the image shown, and then subtract the result image from
the original one to show the differences between them.
code:
x2=imread('F:\Assignment1\images\x2.tif');
for i=1:1024
for j=1:1024
y(i,j)=bitset(x2(i,j),1,0);
end
end
y1=x2-y;
for i=1:1024
for j=1:1024
if y1(i,j)==1
y1(i,j)=0;
else
y1(i,j)=255;
end
end
end
figure;
subplot(1,3,1),imshow(x2),title('original');
subplot(1,3,2),imshow(y),title('proessing');
subplot(1,3,3),imshow(y1),title('difference');
2) Digital subtraction angiography.
code:
x1=imread('F:\Assignment1\images\x3.tif');
x2=imread('F:\Assignment1\images\x4.tif');
y1=x1-x2;
for i=1:420
for j=1:420
y(i,j)=255-y1(i,j);
end
end
figure;
subplot(1,3,1),imshow(x2),title('original');
subplot(1,3,2),imshow(x1),title('x-tay');
subplot(1,3,3),imshow(y),title('final');
Example 2.7 1) If the shading pattern has been estimated from the original image, try to correct
the shading by using image multiplication and division.
code:
x5=imread('F:\Assignment1\images\x5.tif');
x6=imread('F:\Assignment1\images\x6.tif');
x1=double(x5);
x2=double(x6);
y=x1./x2;
figure;
subplot(1,3,1),imshow(x5),title('original');
subplot(1,3,2),imshow(x6),title('sgading pattern');
subplot(1,3,3),imshow(y),title('final');
2) Extraction of ROIs by using mask.
code:
x7=imread('F:\Assignment1\images\x7.tif');
x8=imread('F:\Assignment1\images\x8.tif');
for i=1:674
for j=1:882
if x8(i,j)==255
x8(i,j)=1;
end
end
end
y=x7.*x8;
figure;
subplot(1,3,1),imshow(x7),title('original');
subplot(1,3,2),imshow(x8),title('sgading pattern');
subplot(1,3,3),imshow(y),title('final');
Example 2.8 Let the elements of a gray-scale image be represented by a set A whose elements
are triplets of the form
, where
and
are spatial coordinates and
1) Show the complement of A according to
denotes intensity.
.
2) Suppose image B is a constant image whose size is same as image A, and the value of its
elements is 3 times the mean intensity of image A. Show the union of A and B, with the union of A
and B defined by
1)code:
x1=imread('F:\Assignment1\images\x9.tif');
for i=1:1482
for j=1:750
x2(i,j)=255-x1(i,j);
end
end
figure;
subplot(1,2,1),imshow(x1),title('original');
subplot(1,2,2),imshow(x2),title('Ac');
.
2)code:
x1=imread('F:\Assignment1\images\x9.tif');
a=0;
x4=double(x1);
for i=1:1482
for j=1:750
a=a+x4(i,j);
end
end
n=a/1482/750;
for i=1:1482
for j=1:750
x3(i,j)=max(x1(i,j),23);
end
end
figure;
subplot(1,2,1),imshow(x1),title('original');
subplot(1,2,2),imshow(x3),title('An');
Download