Set color for IJ.run("Draw")

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Set color for IJ.run("Draw")

Christopher Coulon
Hi everyone,

I would like to draw a maximum dark border around my signed 16-bit image in
a plugin.  I tried:

>              StackStatistics stackStats = new StackStatistics(imp);
>             double stackMax = stackStats.max;
>             double threshFactor = 32768d;
>             double maxThresh = stackMax + threshFactor;
>             IJ.run("Select All");
>             IJ.runMacro("setColor("+maxThresh+");");
>             IJ.run("Draw");
>
but the resulting border is ­1034, not the maximum value of ­2048 that I am
trying to get.  It states clearly in the Built-in Macro Functions that
setColor(value) will not change the foreground color used by run(³Draw²),
but is there a way to do this?   Or is IJ.run(³Draw²) limited to 8-bit
images?  Thanks in advance.

Chris Coulon
       

The GAIA Group
Global Automated Image Analysis
http://www.gaiag.net
[hidden email]


We welcome image analysis problems in all fields.

Christopher Coulon, Ph.D., Founder
Reply | Threaded
Open this post in threaded view
|

Re: Set color for IJ.run("Draw")

Wayne Rasband
> I would like to draw a maximum dark border around my signed
> 16-bit image in a plugin.  I tried:
>
>>              StackStatistics stackStats = new StackStatistics(imp);
>>             double stackMax = stackStats.max;
>>             double threshFactor = 32768d;
>>             double maxThresh = stackMax + threshFactor;
>>             IJ.run("Select All");
>>             IJ.runMacro("setColor("+maxThresh+");");
>>             IJ.run("Draw");
>>
> but the resulting border is –1034, not the maximum value of
> –2048 that I am trying to get.  It states clearly in the Built-in
> Macro Functions that setColor(value) will not change the
> foreground color used by run(“Draw”), but is there a way to
> do this?   Or is IJ.run(“Draw”) limited to 8-bit images?  Thanks in  
> advance.

You can draw a 10 pixel border in the image's minimum displayed pixel  
value using:

   border = 10;
   makeRectangle(border, border, getWidth-border*2, getHeight-border*2);
   setBackgroundColor(1, 0, 0);
   run("Clear Outside");

You have to set the background to (1,0,0) because (0,0,0) always sets  
the background color to 0.

To draw the border outside the image use:

   border = 10
   w = getWidth+border*2;
   h = getHeight+border*2;
   setBackgroundColor(1, 0, 0);
   run("Canvas Size...", "width="+w+" height="+h+" position=Center");

Use something like the following to draw the border in an arbitrary  
color:

   requires("1.37e");
   border = 10;
   value = 50;
   w = getWidth+border*2;
   h = getHeight+border*2;
   run("Canvas Size...", "width="+w+" height="+h+" position=Center");
   setColor(value);
   setLineWidth(border*2);
   drawRect(0, 0, getWidth, getHeight);

This requires ImageJ 1.37e, which adds the drawRect() function and  
fixes a bug with the setColor() that caused it to not work correctly  
with signed 16 bit images.

-wayne