ImageJ: How to adjust color of plotted ellipses based on pre-defined RGB values?

76 views Asked by At

I plot ellipses using a txt file which consists all parameters (x,y coordinates, major/minor axes, angle of the major axis) and RGB values for each ellipse. Plotting ellipses is the easy part, however I cannot define the color of ellipses based on the RGB code. I can simply solve this problem with Gnuplot but for other reasons I have to use ImageJ. Can anyone help me with this?

I use this code:

`// 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");
}`
2

There are 2 answers

1
Herbie On

Plotting ellipses is the easy part, however I cannot define the color of ellipses based on the RGB code.

Color.set(value) Sets the drawing color. For 8 bit images, 0<=value<=255. For 16 bit images, 0<=value<=65535. With RGB images, use hex constants (e.g., 0xff0000 for red).

4
Hegmat55 On
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");
}

This was the missing part. It is now working well when RGB image is open.