【发布时间】:2016-09-17 15:06:07
【问题描述】:
抱歉这个愚蠢的问题。我想根据两个矩阵中的值在 matlab 中定义一个 RGB 图像。例如:
A B comparision RGB
|1 0| |1 0| --> |green red |
|1 0| |0 1| --> |purple cyan |
以下代码可以完成这项工作,但非常慢(我知道):
comparision = uint8(zeros([H,W, 3]));
for i=1:H
for j=1:W
if (A(i,j)==1 && B(i,j)==1) %tp
comparision (i,j,:) = [113 140 0];
end
if (A(i,j)==0 && B(i,j)==0) %tn
comparision (i,j,:) = [200 40 41];
end
if (A(i,j)==0 && B(i,j)==1) %fp (false alarm)
comparision (i,j,:) = [10 130 120];
end
if (A(i,j)==1 && B(i,j)==0) %fn
comparision (i,j,:) = [120 20 120];
end
end
end
我很确定使用 matlab 矩阵功能可以更快地完成它。不幸的是,我总是对 matlab 表示法有点困惑,并且没有成功使用谷歌搜索:-/。
我尝试过这样的事情:
comparision(LabelImage1 == 1 & LabelImage2 == 1) = [255 0 0]
但它没有成功。
谁能帮我更快做到这一点?提前致谢
【问题讨论】:
-
第三个和第四个条件有什么区别?他们都有
A(i,j)==0 && B(i,j)==1。 -
哦,谢谢!那只是一个错字