• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ConvolvedOp with / without alpha premultiplication

 
Ranch Hand
Posts: 441
Scala IntelliJ IDE Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm doing some image effects and wondering if ConvolveOp is working correctly. I was doing some filters on images and was getting dark halos around them. I read somewhere that this might be due to not using pre-calculated alpha (i.e. RGB values do not already include the effect of the alpha channel), so I switched my BufferedImage type to TYPE_INT_ARGB_PRE, and it worked as expected (see below).

However I do not understand why the image does not display correctly when using TYPE_INT_ARGB. According to the ConvolveOp documents

This class operates with BufferedImage data in which color components are premultiplied with the alpha component. If the Source BufferedImage has an alpha component, and the color components are not premultiplied with the alpha component, then the data are premultiplied before being convolved. If the Destination has color components which are not premultiplied, then alpha is divided out before storing into the Destination (if alpha is 0, the color components are set to 0). If the Destination has no alpha component, then the resulting alpha is discarded after first dividing it out of the color components.


Doesn't the bolded part mean that non-premultiplied images should work? Or are ConvolvedOp operations only possible on images with premultiplied alpha?


Above: left: BufferedImage type TYPE_INT_ARGB before and after convolution; right: TYPE_INT_ARGB_PRE
 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

This class operates with BufferedImage data in which color components are premultiplied with the alpha component. If the Source BufferedImage has an alpha component, and the color components are not premultiplied with the alpha component, then the data are premultiplied before being convolved. If the Destination has color components which are not premultiplied, then alpha is divided out before storing into the Destination (if alpha is 0, the color components are set to 0). If the Destination has no alpha component, then the resulting alpha is discarded after first dividing it out of the color components.



Hi Luigi. I haven't run any tests, but the highlighted line from the documentation seems to imply that your problem is not caused by not using premultiplied alpha in your source, but in your destination. After the convolve operation, transparent elements may be divided out by simply setting the color to black. Maybe you can try to use a premultiplied source, and filtering to a non-premultiplied destination, and see if you still get the same problem.
 
Luigi Plinge
Ranch Hand
Posts: 441
Scala IntelliJ IDE Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Stephan,

I tried what you suggested, and indeed the same problem happens if the source is premultiplied and the destination isn't.

Likewise if the destination is premultiplied and the source isn't, it renders correctly.

Maybe the solution is just to always use TYPE_INT_ARGB_PRE for your destination image, so there wouldn't be any restriction on what you could convolve, but you would be restricted on the type you end up with.

I don't really care what type I end up with, but presumably there are reasons for sometimes needing a particular image type.
reply
    Bookmark Topic Watch Topic
  • New Topic