求高手做个数字图像处理的问题 要用matlab做啊Take a color picture,program for it to get following results,(1)\x05Its Red,Green and Blue image respectively;(2)\x05Its Hue,Saturation and Intensity image respectively;(3)\x05Do pseudo-col

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/26 07:33:50

求高手做个数字图像处理的问题 要用matlab做啊
Take a color picture,program for it to get following results,
(1)\x05Its Red,Green and Blue image respectively;
(2)\x05Its Hue,Saturation and Intensity image respectively;
(3)\x05Do pseudo-color image processing(assign different colors for
different gray levels);
(4) Detect all edges in the color picture.

答案如下,我接触matlab是在英文环境,简短的写了一些英文注释,不懂的问我,关于第二个,你确定是HSI吗?HSI很少见,但我看了下其他的程序,改了一下,第三题我设的分类较少,你可以再改动,第四题你没有说清楚after detect all edges,是不是应该画出来,我就在color picture中画了.有什么问题再说吧,这一段考试,只能做到这一步了.
function ImageSolution(image)
clc;
I = imread(image);
figure,imshow(I),title('Original Image');
RGB2HSI(I);
pseudocoloring(I);
edgeDetection(I);
clear all;
end
function RGB2HSI(I)
I = im2double(I);
R = I(:,:,1);
G = I(:,:,2);
B = I(:,:,3);%Problem one ends here
figure,imshow(R),title('R Image');
figure,imshow(G),title('G Image');
figure,imshow(B),title('B Image');
th = acos((0.5*((R-G)+(R-B)))./((sqrt((R-G).^2+(R-B).*(G-B)))+eps));
H = th;
H(B>G) = 2*pi-H(B>G);
H = H/(2*pi);
S = 1-3.*(min(min(R,G),B))./(R+G+B+eps);
I = (R+G+B)/3;
HSI = cat(3,H,S,I);
figure,imshow(HSI),title('HSI Image');
figure,imshow(H),title('Hue');
figure,imshow(S),title('Saturation');
figure,imshow(I),title('Intensity');
end
function pseudocoloring(I)
[row column B] = size(I);
BW = rgb2gray(I)/255;
R = I(:,:,1);
G = I(:,:,2);
B = I(:,:,3);
for i = 1:row
for j = 1:column
if 0 < BW(i,j) < 0.4
R(i,j) = BW(i,j) * R(i,j);
G(i,j) = BW(i,j) * G(i,j);
B(i,j) = BW(i,j) * B(i,j);
end

if 0.4 < BW(i,j) < 0.7
R(i,j) = R(i,j) - BW(i,j);
G(i,j) = G(i,j) - BW(i,j);
B(i,j) = B(i,j) - BW(i,j);
end

if 0.7 < BW(i,j) < 1.0
R(i,j) = R(i,j) + BW(i,j);
G(i,j) = G(i,j) + BW(i,j);
B(i,j) = B(i,j) + BW(i,j);
end
end
end
assignI = cat(3,R,G,B);
figure,imshow(BW),title('Gray level image');
figure,imshow(assignI),title('Gray level assigned color image');
end
function edgeDetection(I)
BW = rgb2gray(I);
R = I(:,:,1);
G = I(:,:,2);
B = I(:,:,3);
edgeI = edge(BW);
figure,imshow(edgeI),title('Edge in BW image');
[row column] = size(BW);
for i = 1:row
for j = 1:column
if edgeI(i,j) == 1%This is edge
R(i,j) = 0;%Set edge in color image as black color
G(i,j) = 0;
B(i,j) = 0;
end
end
end
edgeColorI = cat(3,R,G,B);
figure,imshow(edgeColorI),title('Edge in color image');
end