I am working with dorsal fins and getting their general shape. I am able to use the Bezier curve to outline the shape well, but I need the outline to be on an alpha channel that can be saved and passed on from person to person (only some of which are using imageJ and others using other similar programs). I have been able to get the outline on an overlay, but when I save it flattens the image and isn’t transferable. Any thoughts how to solve this?
It is possible with ImageJ to save an Alpha-channel when saving an RGB-image as PNG.
Thanks Herbie, I’m still not having any luck getting the macro to work
Starting with the ImageJ 1.47o daily build, the File>Save As>PNG command saves 4-image 8-bit stacks, or hyperstacks, as PNG with alpha if the label of the fourth image is “Alpha”.
Here is a “stand alone”-macro that works for me:
run( "Lena (68K)" ); setBatchMode( true ); run( "Make Composite" ); run( "Add Slice", "add=channel prepend" ); run( "Set Label...", "label=Alpha" ); setForegroundColor( 64, 64, 64 ); setLineWidth( 3 ); setBatchMode( false ); waitForUser( "Please draw the desired selection.\nThen click OK." ); run( "Draw", "slice" ); run( "Select None" ); home = getDirectory( "home" ); saveAs( "PNG", home + "lenaPlusAlpha.png" );
Paste the code to an empty macro window (Plugins >> New >> Macro) and run it.
You need an open Internet-connection to let the macro load the example image.
The resulting PNG-image with Alpha-channel is saved in your home directory.
That worked perfectly. It is exactly what I need, however, now I am unsure how to apply it to my images. Sorry, very new at this.
I am unsure how to apply it to my images.
Not perfectly sure what the problem is but evidently the first line of my macro loads the Lena-image from the NIH-website via the internet, i.e. you can omit it or comment it, i.e. like so:
//run( "Lena (68K)" );
Next you may want to save the PNG-image with the alpha-overlay. This is done in the last line of my macro by using the command:
saveAs( "PNG", home + "lenaPlusAlpha.png" );
Of course, you want to use a file name of your choice or keep the name of the initial image. In this case the easiest solution is to replace the last line of my macro by:
saveAs( "PNG" );
In this case a “Save File”-dialog will be presented in which you can select the desired folder and perhaps change the file name.
In this case you can omit or comment the line before, i.e. like so:
//home = getDirectory( "home" );
Furthermore, it is always helpful to get acquainted with the macro language:
Thanks, that did it. but when I emailed it the layers flattened. I’ll figure it out. Thanks
You can check whether there is an alpha-channel in the PNG-image:
Open the PNG-image in ImageJ and go to “Image >> Show Info…”.
If “Bits per pixel” is 32, then there is an alpha-channel.
(A pure RGB-image has three 8bit channels which makes 24bits.)
Evidently ImageJ does not allow to access the alpha-channel of an PNG-image and I don’t know which software does.
If you want to save an alpha-channel that is accessible for ImageJ, then you should additionally (to the PNG-image) save the 4-channel image as TIF-image. After you’ve opened such a 4-channel TIF-image you should access the “Channels Tool” to navigate and select single channels (Image >> Color >> Channels Tool…).