用MATLAB实现对灰度图像到彩色图像的变换?

部分程序,希望补全。
I=imread(‘i_boat.bmp’);
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

第1个回答  2011-12-13
clear all;close all;clc;
I=imread('i_boat.jpg');
imshow(I);
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;
figure
imshow(G2C)
G2C=rgb2gray(G2C)
figure
imshow(G2C)本回答被提问者采纳
相似回答