Posted by
Michael Schmid on
May 19, 2010; 4:37pm
URL: http://imagej.273.s1.nabble.com/Every-time-an-image-is-opened-tp3688256p3688258.html
Hi Scott,
Here is a very simple plugin that registers as an ImageListener. You
can call it in your StartupMacros.txt.
import ij.*;import ij.plugin.*;
public class Always_Open_16bit_Fullscale implements PlugIn,
ImageListener {
public void run(String arg) {
ImagePlus.addImageListener(this);
}
public void imageOpened(ImagePlus imp) {
//if it does not work, add this: IJ.wait(100);
if (imp.getType()==ImagePlus.GRAY16) imp.setDisplayRange(0,
65535);
imp.updateAndDraw();
}
public void imageClosed(ImagePlus imp){}
public void imageUpdated(ImagePlus imp){}
}
You should call it only once; otherwise you should add some
'singleton' code.
Concerning drawing: if you only want to draw points, you could also
create your own drawing macro tool that uses the setPixel(x, y,
value) command to draw with a fixed value rather than a color that
depends on the display range. Drawing 1-pixel-wide lines would be
also possible, but slightly more complex code.
Michael
________________________________________________________________
On 19 May 2010, at 17:06, SHW wrote:
> General:
> Is there way to do an action/Macro/etc. every time an image is opened,
> automatically?
>
> I would please like to know the actual answer to my question, as it
> applies
> to many other situations also. Other workarounds for this specific
> situation may be helpful, and would be appreciated, but would not
> address
> the issue in general. Therefore, my specific problem is listed below.
>
> I appreciate any and all help.
> - Scott Williams, PhD -
>
>
> Specific:
> I have 2048x2048 16-bit grayscale scale images. ImageJ
> automatically sets
> Min and Max display values to the smallest and largest value in the
> file,
> respectively, which are often NOT 0 and 65535. I can manually set
> these
> values through Balance and Contrast (B&C)>[Set], or use setMinAndMax
> () in a
> macro to do the same. But any time I go to B&C, the [Reset] button
> goes
> back to these values. I do not want this "option".
> Additionally, this default value range actually PROHIBITS the
> manual drawing
> of any value higher than the largest in the file. Even if I set
> the Pencil
> to 255,255,255, it does not draw an actual white of 65565.
>
> My current workaround is to draw a single Black pixel in the upper
> left, and
> a single White pixel in the lower right, through a macro with:
> setPixel (0,0,0)
> setPixel (2047,2047,65535)
>
> This will ensure that B&C [Reset] never shows lower than the full
> 16-bit
> range. Also, it will ensure that that I can manually draw true White.
>
> I would like a way for this simple macro to apply, automatically,
> each and
> every time I open an image.
>
>
> Long-term, I might suggest:
> - adding a [Full] button to the B&C pop-up menu
> - relabeling the [Reset] button as something more appropriate,
> perhaps
> [Range], and
> - making the "auto-[Range]-on-Open" a Option somewhere which could be
> enabled/disabled.