Hi,
I am trying to add information to the alpha channel of a color image and save it to file with the alpha channel as this: run("Clown (14K)"); wdth = getWidth(); hgth = getHeight(); for(i=0;i<wdth;i++)for(j=0;j<hgth;j++)setPixel(i,j,getPixel(i,j)&0xFFFFFF+0x01000000*round(255*i/wdth)); saveAs("PNG", "E:\\Clown.png"); Unfortunately the alpha channel is not saved and I get a strange result from transparencies above 0x7F (I guess it is connected with the sign of the 32 bit number written by setPixel). I would also like to save to PNG without compression, is it possible? Best, Sébastien -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Sébastien,
ImageJ does not support the alpha channel. The only thing supported is having a single transparent color in an indexed-color file (Edit>Options>Input/Output>GIF & PNG transparent index). If you want to blend images with variable weight, you can use the Alpha Channel plugin: http://imagejdocu.tudor.lu/doku.php?id=plugin:utilities:alpha_channel:start Michael ________________________________________________________________ On Mar 26, 2013, at 10:53, Sébastien Tosi wrote: > Hi, > > I am trying to add information to the alpha channel of a color image and save it to file with the alpha channel as this: > > run("Clown (14K)"); > wdth = getWidth(); > hgth = getHeight(); > for(i=0;i<wdth;i++)for(j=0;j<hgth;j++)setPixel(i,j,getPixel(i,j)&0xFFFFFF+0x01000000*round(255*i/wdth)); > saveAs("PNG", "E:\\Clown.png"); > > Unfortunately the alpha channel is not saved and I get a strange result from transparencies above 0x7F (I guess it is connected with the sign of the 32 bit number written by setPixel). I would also like to save to PNG without compression, is it possible? > > Best, > Sébastien -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Sebastien
Hi Michael,
Thanks for your help. I am mostly interested in saving RGBA images to disk from ImageJ, not really displaying or creating them (it seems that the macro I previously posted writes in the alpha channel, even if the image is not properly displayed). Is there a way to save such images without writing a specific plugin? Sébastien -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Sebastien
Hello Sébastien,
look at my website that saves non rectangular-objects (perspective stack slices) so that they blend nicely with any gradient background e.g. in Powerpoint: http://simon.bio.uva.nl/objectj/examples/PerspectiveStackView/PerspectiveStackView.htm This type of slides were used in my Luxembourg presentation 2012 about the GlassWindow. Look for the macro "Save As PNG with transparent background [3]" regards, Norbert On 26. Mar 2013, at 10:53, Sébastien Tosi wrote: > I am trying to add information to the alpha channel of a color image and save it to file with the alpha channel as this: > > run("Clown (14K)"); > wdth = getWidth(); > hgth = getHeight(); > for(i=0;i<wdth;i++)for(j=0;j<hgth;j++)setPixel(i,j,getPixel(i,j)&0xFFFFFF+0x01000000*round(255*i/wdth)); > saveAs("PNG", "E:\\Clown.png"); > > Unfortunately the alpha channel is not saved and I get a strange result from transparencies above 0x7F (I guess it is connected with the sign of the 32 bit number written by setPixel). I would also like to save to PNG without compression, is it possible? -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hello Sébastien,
Well I have to add that my suggested macro does not export semi-transparency, but leaves the process of shadow-blending to PowerPoint... Norbert On 27. Mar 2013, at 23:35, Norbert Vischer wrote: > Hello Sébastien, > > look at my website that saves non rectangular-objects (perspective stack slices) so that > they blend nicely with any gradient background e.g. in Powerpoint: > > http://simon.bio.uva.nl/objectj/examples/PerspectiveStackView/PerspectiveStackView.htm > > > This type of slides were used in my Luxembourg presentation 2012 about the GlassWindow. > Look for the macro > "Save As PNG with transparent background [3]" > > regards, Norbert > > I am trying to add information to the alpha channel of a color image and save it to file with the alpha channel as this: > > run("Clown (14K)"); > wdth = getWidth(); > hgth = getHeight(); > for(i=0;i<wdth;i++)for(j=0;j<hgth;j++)setPixel(i,j,getPixel(i,j)&0xFFFFFF+0x01000000*round(255*i/wdth)); > saveAs("PNG", "E:\\Clown.png"); > > Unfortunately the alpha channel is not saved and I get a strange result from transparencies above 0x7F (I guess it is connected with the sign of the 32 bit number written by setPixel). I would also like to save to PNG without compression, is it possible? -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
On Wednesday 27 Mar 2013 23:21:33 you wrote:
> Well I have to add that my suggested macro does not export > semi-transparency, but leaves the process of shadow-blending to > PowerPoint... Hi Norbert, That is a very nice animation. I found that this works as far as the background is NOT set to "Black background" in the Process>Binary>Options Maybe a test can be added to see how that flag is set and process the result accordingly so it works in both cases? Just an idea: it would be interesting to have an option so the slices mix additively when overlapping. (so red + green is yellow and so on) and the last image with all the planes superimposed is the RGB composite. Thanks for sharing this. Cheers Gabriel -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Sebastien
Hello Norbert,
Thank you, this is a good trick. Unfortunately it does not really help me as I wanted to use the alpha channel of an RGB image to store an 8-bit image, save the resulting RGBA image to file, process it outside ImageJ and finally load the result and split the 4 components in ImageJ. Best, Sébastien -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Sébastien,
On Fri, 29 Mar 2013, Sébastien Tosi wrote: > Thank you, this is a good trick. Unfortunately it does not really help > me as I wanted to use the alpha channel of an RGB image to store an > 8-bit image, save the resulting RGBA image to file, process it outside > ImageJ and finally load the result and split the 4 components in ImageJ. You cannot do that with macros (as I do not tire of pointing out, the macro language is very nice in that it is simple, but sometimes you need to access the full Java API, i.e. go at least to Javascript). Ciao, Johannes -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Sebastien
Hi Sébastien,
find a Beanshell script that demonstrates how to do it here https://github.com/axtimwalde/fiji-scripts/blob/master/open-modify-show-save-alpha-png.bsh I am certain that you'll find your way through. Best, Stephan On Fri, 2013-03-29 at 08:59 -0400, Sébastien Tosi wrote: > Hello Norbert, > > Thank you, this is a good trick. Unfortunately it does not really help > me as I wanted to use the alpha channel of an RGB image to store an > 8-bit image, save the resulting RGBA image to file, process it outside > ImageJ and finally load the result and split the 4 components in > ImageJ. > > Best, > Sébastien > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Sebastien
Great, exactly what I was looking for! Thank you!
S. -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
On 29. Mar 2013, at 16:28, Stephan Saalfeld wrote:
> find a Beanshell script that demonstrates how to do it here > https://github.com/axtimwalde/fiji-scripts/blob/master/open-modify-show-save-alpha-png.bsh Thanks Stephan for making this nice beanshell example available. I got it working both in Fiji and in the ImageJ Beanshell window. To make this usable for people who are not familiar with programming, it would be nice if one simply could save any existing 4-slice (hyper)stack as PNG + alpha without changing code. And, even better, this could become an integral part of ImageJ whenever the user attempts to save a 4-slice (hyper)stack as .PNG. On 28. Mar 2013, at 10:05, Gabriel Landini wrote: > That is a very nice animation. I found that this works as far as the > background is NOT set to "Black background" in the Process>Binary>Options Gabriel, thank you for detecting this well-hidden bug! In the new version, I simply set the flag to my needs. > Just an idea: it would be interesting to have an option so the slices mix > additively when overlapping. (so red + green is yellow and so on) and the last > image with all the planes superimposed is the RGB composite. Adding transparency during animation surely could be done- my intention so far was only to demonstrate what a hyperstack is. Further, I wait how this thread will develop because full support for the alpha channel would considerably simplify my "perspective" project. cheers, Norbert -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
On Mar 30, 2013, at 2:00 PM, Norbert Vischer wrote:
> On 29. Mar 2013, at 16:28, Stephan Saalfeld wrote: > >> find a Beanshell script that demonstrates how to do it here >> https://github.com/axtimwalde/fiji-scripts/blob/master/open-modify-show-save-alpha-png.bsh Here is an updated version of Stephan's BeanShell script that uses the ColorProcessor.getChannel() and ColorProcessor.setChannel() methods to extract and restore the alpha channel. It requires the ImageJ 1.47o daily build, which adds alpha channel support to getChannel() and setChannel(). The 1.47o daily build also adds the IJ.getFilePath(dialogTitle) method used by the script. http://imagej.nih.gov/ij/macros/bsh/Open_Modify_Save_Alpha_PNG.bsh -wayne /** * Open, modify, save and show a PNG image with an alpha * channel. This script's purpose is to demontrate how this * can be done and where ImageJ needs to be bypassed. For * real data processing, I suggest to transfer it into a * Java plugin as single pixel processing is prohibitively * slow from Beanshell. * * Requires ImageJ 1.47o or later. * * @author Stephan Saalfeld */ import javax.imageio.ImageIO; import java.awt.image.BufferedImage; /* open a PNG with alpha into a ColorProcessor */ path = IJ.getFilePath("Open PNG with alpha"); cp = new ColorProcessor(ImageIO.read(new File(path))); w = cp.getWidth(); h = cp.getHeight(); /* get the alpha channel and punch a hole into it */ bpAlpha = cp.getChannel(4, null); r = Math.min(w, h)/4; roi = new OvalRoi(w/2-r, h/2-r, 2*r, 2*r); bpAlpha.setValue(0); bpAlpha.fill(roi); /* restore the modified alpha channel and create a BufferedImage */ cp.setChannel(4, bpAlpha); cp2Image = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); raster = cp2Image.getRaster(); raster.setDataElements(0, 0, w, h, cp.getPixels()); /* save and show the modified image */ path2 = path + "-modified.png"; ImageIO.write( cp2Image, "png", new File(path2)); IJ.open(path2); -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by vischer
On Mar 30, 2013, at 2:00 PM, Norbert Vischer wrote:
> On 29. Mar 2013, at 16:28, Stephan Saalfeld wrote: > >> find a Beanshell script that demonstrates how to do it here >> https://github.com/axtimwalde/fiji-scripts/blob/master/open-modify-show-save-alpha-png.bsh > > > Thanks Stephan for making this nice beanshell example available. > > I got it working both in Fiji and in the ImageJ Beanshell window. > To make this usable for people who are not familiar with programming, it would be nice if one simply could save any existing 4-slice (hyper)stack as PNG + alpha without changing code. > > And, even better, this could become an integral part of ImageJ whenever the user attempts to save a 4-slice (hyper)stack as .PNG. 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". Norbert Vischer's Perspective Stack View macro at http://simon.bio.uva.nl/objectj/examples/PerspectiveStackView/PerspectiveStackView.htm uses this new feature to save perspective views as PNG files with transparent backgrounds. -wayne > On 28. Mar 2013, at 10:05, Gabriel Landini wrote: >> That is a very nice animation. I found that this works as far as the >> background is NOT set to "Black background" in the Process>Binary>Options > > Gabriel, thank you for detecting this well-hidden bug! In the new version, I simply set the flag to my needs. > >> Just an idea: it would be interesting to have an option so the slices mix >> additively when overlapping. (so red + green is yellow and so on) and the last >> image with all the planes superimposed is the RGB composite. > > Adding transparency during animation surely could be done- my intention so far was only to demonstrate what a hyperstack is. > > Further, I wait how this thread will develop because full support for the alpha channel would considerably simplify my "perspective" project. > > cheers, Norbert > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Gabriel Landini
>
> Just an idea: it would be interesting to have an option so the slices mix > additively when overlapping. (so red + green is yellow and so on) and the last > image with all the planes superimposed is the RGB composite. > > Thanks for sharing this. > > Cheers > > Gabriel Hello Gabriel, I have implemented your idea: additive color mixing during overlap can now be demonstrated by setting checkbox "Color Mixing". best regards, Norbert http://simon.bio.uva.nl/objectj/examples/PerspectiveStackView/PerspectiveStackView.htm -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |