ImageJ:如何根据预定义的 RGB 值调整绘制的椭圆的颜色?

问题描述 投票:0回答:2

我使用 txt 文件绘制椭圆,该文件包含每个椭圆的所有参数(x、y 坐标、长轴/短轴、长轴角度)和 RGB 值。绘制椭圆是简单的部分,但是我无法根据 RGB 代码定义椭圆的颜色。我可以用 Gnuplot 简单地解决这个问题,但由于其他原因我必须使用 ImageJ。谁能帮我解决这个问题吗?

我使用这个代码:

`// import file with coordinates, major and minor axis, angle of rotation (CW degrees)
fileName = File.openDialog("Select the file to import");
allText = File.openAsString(fileName);
text = split(allText, "\n");

for (i = 0; i < text.length; i++) {
    line = split(text[i], ",");
    XM = parseFloat(line[1]); // Assuming the X coordinate is in the first column
    YM = parseFloat(line[2]); // Assuming the Y coordinate is in the second column
    Major = parseFloat(line[3]); // Assuming the major axis is in the third column
    Minor = parseFloat(line[4]); // Assuming the minor axis is in the fourth column
    Angle = parseFloat(line[5]); // Assuming the rotation angle is in the fifth column

run("Specify...", "width=" + Major + " height=" + Minor + " x=" + XM + " y=" + YM + " oval       centered");
   run("Rotate...", "angle=" + Angle+90);
   run("Draw");
   roiManager("add");
}`
colors imagej data-fitting imagej-macro drawellipse
2个回答
0
投票

绘制椭圆是简单的部分,但是我无法定义颜色 基于 RGB 代码的椭圆。

颜色.设置(值) 设置绘图颜色。对于 8 位图像,0<=value<=255. For 16 bit images, 0<=value<=65535. With RGB images, use hex constants (e.g., 0xff0000 for red).


0
投票
R = parseInt(line[9]);
G = parseInt(line[10]);
B = parseInt(line[11]); 

setColor(R, G, B);

run("Specify...", "width=" + Major + " height=" + Minor + " x=" + XM + " 
y=" + YM + " oval centered");
run("Rotate...", "angle=" + Angle);
run("Draw");
run("Fill");
roiManager("add");
}
function setColor(r, g, b) {
setForegroundColor(r, g, b);
run("Select None");
}

这就是缺失的部分。现在,当 RGB 图像打开时,它可以正常工作。

© www.soinside.com 2019 - 2024. All rights reserved.