【发布时间】:2011-11-29 17:32:35
【问题描述】:
我正在编写一个用于在图像中画线的函数文件。现在我面临颜色问题。如果我在命令窗口中设置color=[255 255 255] 或color=[128 128 128],图像中出现的线条都是白色的。
[128 128 128],应该是灰色吧?这与颜色表不对应。我已经测试了一些颜色的值,结论是它取任何大于零的数字作为 255。我该如何解决这个问题?
以下是我的代码。
function [ret]=drawline(p1,p2,color,img);
xmax=size(img,1);
ymax=size(img,2);
if (p1(1)>xmax) || (p2(1)>xmax) || (p1(2)>ymax) || (p2(2)>ymax)
error('value of point is ouside the image.');
elseif (p1(1)==xmax) || (p2(1)==xmax) || (p1(2)==ymax) || (p2(2)==ymax)
error('warning: value of point reach the max.');
elseif (color(1)>256) ||(color(2)>256)||(color(3)>256)
error('color value is out of range.');
else
m=(p2(2)-p1(2))/(p2(1)-p1(1));
m=round(m);
c=p1(2)-m*p1(1);
for x=linspace(p1(1),p2(1),1000)
y=m*x+c;
if p1(1)==p2(1)
x=p1(1);
y=p1(1):p2(2);
end
img(round(y),round(x),1)=color(1);
img(round(y),round(x),2)=color(2);
img(round(y),round(x),3)=color(3);
end
end
ret=img
【问题讨论】:
-
请贴出你到目前为止所做的代码。
-
我已经发布了代码...谢谢!