Line Tool to ROI Manager with different colors

Tags: #<Tag:0x00007fd69c2ceaa0> #<Tag:0x00007fd69c2ce960>


Dear all,

I’m looking for an option or plugin that allows me to add several lines (drawn with the segmented line tool) to the ROI manager (or something comparable) and assign them to a certain “class”, i.e. in the easiest sense assign different colors to them according to the class I’m defining. Basically, like a Cell Counter plugin for lines that still allows subsequent length measurements from manually drawn lines in the image…

I couldn’t find anything so far…

Thanks for your help!


Good day Patrick!

Because I’m just in a hurry, you may have a look at a related problem discussed and solved here:

Please note that not only the fill color of selections but also the line colors can be set/changed.

I shall have a look at your problem tomorrow in case nobody else does.




Well Patrick,

here is a macro that allows you to change the color of line selections to your liking.

Create a simple test image:

newImage( "LineSelections", "8-bit black", 256, 256, 1 );
roiManager("Show All");

Paste the above macro code to an empty macro window (Plugins >> New >> Macro) and run it.

Colorizer macro:

idx = roiManager( "count" );
rois = Array.getSequence( idx );
for ( i=0; i < idx; i++ ) { rois[i] = d2s( 1+rois[i], 0 ); }
Dialog.create("Set Line Color");
Dialog.addChoice( "Index", rois );
//Dialog.addSlider( "Opacity", 0, 255, 128 );
Dialog.addSlider( "Red", 0, 255, 0 );
Dialog.addSlider( "Green", 0, 255, 0 );
Dialog.addSlider( "Blue", 0, 255, 0 );;
idx = parseInt( Dialog.getChoice() ) - 1;
c = "";
//c =       padStr( toHex( Dialog.getNumber() ) );
c = c + padStr( toHex( Dialog.getNumber() ) );
c = c + padStr( toHex( Dialog.getNumber() ) );
c = c + padStr( toHex( Dialog.getNumber() ) );
roiManager( "select", idx );
//roiManager( "Set Fill Color", c );
roiManager("Set Color", c );
run("Select None");
function padStr( hex ) {
	if ( lengthOf( hex ) < 2 ) { return "0" + hex; } else { return hex; }

Paste the above macro code to another empty macro window (Plugins >> New >> Macro) and run it.

Here is an example of the colored test image:

[…] i.e. in the easiest sense assign different colors to them according to the class I’m defining.

If you would like to see this automatically performed, you need to provide the mathematically formulated class definitions.




Dear @Herbie,

thanks a lot for your help! This would make it already easier to get along!

Maybe I can also link here another topic about which I just posted. The example that is shown there is the data that I’m trying to analyze.

The different color classes I’m looking for, would serve as a tag, basically, and allow me to better annotate the different signals in these datasets and measure them individually based on the class they belong to. Like this, I could go over the images once and annotate all different signals and signal combinations (there are certain different combinations I’m interested in) right away, like illustrated in the image below (white corresponds to the distance between the two red signals as an example)

Maybe you know better, but I don’t see a way to assign the respective color (or tag) in the final measurement to the respective signal. I imagine something like a measurement table (like the one I get using the multiple measurement function in the ROI manager) where I have my length measurements listed along with the color/tag. Is there a way of implementing this?

Thanks again for your help!




I must admit that I don’t really understand the goal of your analyses.

For instance

[…] white corresponds to the distance between the two red signals as an example)

remains obscure to me. I can’t link it to your image data.

What is the role of color in your analyses and where does it come from. More details are necessary but as mentioned in referring to your other post: The image data is of minor quality and I see little hope for reliable and fully automated analyses.





I apologize that my explanation is not detailed enough.

The signals you are looking at are elongated and individual DNA molecules. More specifically, the red and green signals are two individual incorporated nucleotides that, in combination, allow me to identify certain signals. The DNA itself is not shown in this example. The measurements I’m performing then are basically length measurements of these colored “tracks”. From these lengths values, I can then calculate different parameters important for my research question.

In the context of this experiment, the different colors would allow me to assign the different length measurements to different classes (i.e. track length of either signal, distances between signals, etc) that are then used for different calculations of the different parameters. So, I’m basically looking for a way to better annotate my data in this case. Not exactly direct “automated measurement” in this case.

Regarding image quality: these images contain single DNA molecules of ~2nm diameter stretched out on a glass coverslips. The different signals are detected by immunofluorescence staining, hence the strong background (from unspecific antibody binding, antibody precipitates, etc). The images are acquired with a 63x objective on a widefield microscopic system. And I need to image very large areas of the coverslip to cover as many signals as possible, which is difficult given the very narrow depth of focus for that sample.

So far, I really could not find a better way to improve image acquisition. But if you have any suggestions on that as well, now that you know more about the technical aspect, I would be happy to hear about it.

I hope this helps!

Thanks again and kind regards,




I don’t uderstand how the overlapping strands are to be interpreted, i.e. the yellow parts. Are these sequences that are labled by both stains?

I don’t think it is a good idea to acquire large object areas. I think it is better to acquire smaller and overlapping areas and try to improve their quality and then anlyze them separately. i.e. without any stiching.

How do you image 2nm structures??




The individual signals result from modified nucleotides that are incorporated into the DNA by the cells during synthesis (you can grow cells in medium containing such nucleotide analogs and they will use them for DNA duplication). I apply two different ones sequentially, thus I get two different signals.

Overlapping signals mean, basically, that residual nucleotide from the first label get incorporated while I apply the second analog. This can be avoided only to a certain degree (exhaustion of the first analog is required). The combination of TWO signals, however, is used to better identify distinct “sites” on the DNA molecules, i.e. start sites for DNA duplication. But as I say, only a certain combination of signals can be used for analysis anyway, and overlapping signals are not a problem for the actual measurement.

Here is an example of all the signals I get, including DNA strands (in blue). I guess you see how messy these images are with all the strong background for example on the left…

Since the signals are so small, extremely distributed (due to the biological nature of DNA replication) and relatively little in number, I rely on imaging large areas. Otherwise, already imaging would take weeks for one single sample (not to speak of replicate experiments…).

The 2nm is for the DNA diameter. What I’m actually imaging here are the antibodies that bind to the DNA/analogs - which are much larger and are coupled to fluorescent dyes. So the signal coming from these point sources, and due to the fact that it is amplified along the DNA molecules, makes imaging possible.

Hope this helps :slight_smile:




how comes that the strands are now in blue?

In general, I think you should be a bit more consistent in how you explain people, who are not immediately involved in your work, how your signals look like and what exactly is the desired outcome of the analyses. The latter is still opaque to me.

For example:

What would be the desired outcome of the analysis of the above strand. Please be as precise as possible and don’t forget that computers can’t handle qualitative descriptions. What we need are quantitative formulations.

My question regarding the imaging of 2nm structures was more subtle and of course it was rhetorical. Obviously the message didn’t arrive.

If you are mainly interested in the lengths of strands, then their patchyness appears to be the greatest problem and it needs to be minimized during image acquisition and perhaps the biochemical preparation of the strands.

The dot-like surrounding structures are less annoying for any kind of automatic analyses.

Since the signals are so small, extremely distributed (due to the biological nature of DNA replication) and relatively little in number, I rely on imaging large areas.

If the images you’ve posted before are excerpts from the large ones, then I doubt this statement.





here is the best binarized version

of the red channel

of this image

that I could achieve. However, I fear that length measurements aren’t possible due to the kind of my processing.

In general I very much hope you’re not working with JPEG-compressed images anywhere in your processing chain.