资源描述
Digital Image Processing
Project chapter: Chapter 6
Project number: Proj06-01 ~ Proj06-04
Student's name:
Student's number:
Class:
Contents
WEB-SAFE COLORS 2
PSEUDO-COLOR IMAGE PROCESSING 2
COLOR IMAGE ENHANCEMENT BY HISTOGRAM PROCESSING 5
COLOR IMAGE SEGMENTATION 7
Web-Safe Colors
Exp. 20,PROJECT 06-01
Objective
To know what are Web-safe colors, how to generate the RGB components for a given jpeg color image, or convert an image to RGB manually?
Requirements
(a) Write a computer program that converts an arbitrary RGB color image to a web-safe RGB image (see Fig. 6.10 for a definition of web-safe colors).
(b) Download the image in Fig. 6.8 and convert it to a web-safe RGB color image. Figure 6.8 is given in jpg format, so convert your result back to jpg (see comments at the beginning of this project).
9
Figure 1 Fig6.08.jpg
Technical discussion
【1】B = fix(A)
rounds the elements of A toward zero, resulting in an array of integers.For complex A, the imaginary and real parts are rounded independently.
【2】imwrite(A,filename,fmt)
writes the image A to the file specified by filename in the format specified by fmt.
Program listings
I=imread('Fig6.08.jpg');
subplot(131);
imshow(I);
title('original');
I1=fix((I/51)*51);
subplot(132);
imshow(I1);
title('web-safe colors(jpg)');
imwrite(I1,'web-safe colors.jpeg','jpeg');
subplot(133);
I=imread('web-safe colors.jpeg');
imshow(I);
title('web-safe colors(jpeg)');
Discussion of results
Figure 2 results of project 06-01
Pseudo-Color Image Processing
Exp. 21,PROJECT 06-02
Objective
To know when the highpass filtering Hhp(u,v) can be obtained by using the relation 1-Hlp(u,v).
Requirements
(a) Implement Fig. 6.23, with the characteristic that you can specify two ranges of gray-level values for the input image and your program will output an RGB image whose pixels have a specified color corresponding to one range of gray levels in the input image, and the remaining pixels in the RGB image have the same shade of gray as they had in the input image.
(b) Download the image in Fig. 6.22(a) and process it with your program so that the river appears yellow and the rest of the pixels are the same shades of gray as in the input image.
Figure 3 Fig6.22(a).jpg
Technical discussion
【1】RGB components
rgb_R=I(:, :, 1);
rgb_G=I(:, :, 2);
rgb_B=I(:, :, 3);
Program listings
I=imread('Fig6.22(a).jpg');
subplot(121);
imshow(I);
title('original');
I=double(I);
[m,n]=size(I);
L=256;
for i=1:m
for j=1:n
if I(i,j)<L/4
R(i,j)=0;
G(i,j)=4*I(i,j);
B(i,j)=L;
else if I(i,j)<=L/2
R(i,j)=0;
G(i,j)=L;
B(i,j)=-4*I(i,j)+2*L;
else if I(i,j)<=3*L/4
R(i,j)=4*I(i,j)-2*L;
G(i,j)=L;
B(i,j)=0;
else
R(i,j)=L;
G(i,j)=-4*I(i,j)+4*L;
B(i,j)=0;
end
end
end
end
end
for i=1:m
for j=1:n
G2C(i,j,1)=R(i,j);
G2C(i,j,2)=G(i,j);
G2C(i,j,3)=B(i,j);
end
end
G2C=G2C/256;
subplot(122);
imshow(G2C);
title('Pseudo-Color');
Discussion of results
Figure 4 results of project 06-02
Color Image Enhancement by Histogram Processing
Exp. 22,PROJECT 06-03
Objective
To know how to implement image enhancement for color images by histogram processing. Note that the definition of histogram for color images differs from that of histogram for gray images.
Requirements
Download the dark-stream color picture in Fig. 6.35. Histogram-equalize the R,G,and B images separately using the histogram-equalization program and convert the imageback to jpg format.
Figure 5 Fig6.35(5).jpg
Technical discussion
【1】C = cat(dim, A1, A2, A3, A4, ...)
concatenates all the input arrays (A1, A2, A3, A4, and so on) along array dimension dim.
Program listings
I=imread('Fig6.35(5).jpg');
subplot(121);
imshow(I);
title('original');
a=I(:,:,1);
b=I(:,:,2);
c=I(:,:,3);
A=histeq(a);
B=histeq(b);
C=histeq(c);
I3=cat(3,A,B,C);
subplot(122);
imshow(I3);
title('histogram processing');
Discussion of results
Figure 6 results of project 06-03
Color Image Segmentation
Exp. 23,PROJECT 06-04
Objective
Color image segmentation is a big issue in image processing. This students need to know the basics of this topic.
Requirements
Download Fig. 6.28(b) and duplicate Example 6.15, but segment instead the darkest regions in the image.
Figure 7 Fig6.30(01).jpg
Technical discussion
【1】 RGB2 = im2double(RGB)
converts the truecolor image RGB to double precision, rescaling the data if necessary
Program listings
rgb=imread('Fig6.30(01).jpg');
subplot(221);
imshow(rgb);
title('original');
rgb1=im2double(rgb);
r=rgb1(:,:,1);
g=rgb1(:,:,2);
b=rgb1(:,:,3);
r1=r(129:256,86:170);
r1_u=mean(mean(r1(:)));
[m,n]=size(r1);
sd1=0.0;
for i=1:m
for j=1:n
sd1=sd1+(r1(i,j)-r1_u)*(r1(i,j)-r1_u);
end
end
r1_d=sqrt(sd1/(m*n));
r2=zeros(size(rgb1,1),size(rgb1,2));
ind=find((r>r1_u-1.25*r1_d)&(r<r1_u+1.25*r1_d));
r2(ind)=1;
subplot(222);
imshow(r2);
title('segmentation');
subplot(234);
imshow(r);
title('R component');
subplot(235);
imshow(g);
title('G component');
subplot(236);
imshow(b);
title('B component');
Discussion of results
Figure 8 results of project 06-04
展开阅读全文