Message Boards Message Boards

5
|
8745 Views
|
4 Replies
|
7 Total Likes
View groups...
Share
Share this post:

What is the logic of transparency handling by image-processing functions?

Posted 7 years ago

When working on this post I discovered that starting from Mathematica 10.0 the behavior of such functions as Blur, GaussianFilter, ImageConvolve and some others was changed. Namely, they no longer affect alpha channel of an Image they are applied to. Unfortunately the Documentation is completely silent about this important change which has broken all dependent code, including this ingenious function written by Heike.

My interpretation was that the purpose of this incompatible change is to make transparency handling by all image processing functions be consistent. In versions 8 and 9 ImageAdjust, Dilation and some other similar functions weren't applied to alpha channel. The consistent implementation is to make them all to ignore alpha channel or make them all to process alpha channel (or, better, make this behavior optional). But further investigation showed that even in the latest version 11.2.0 there are strongly related functions which still affect alpha channel: ImageCorrelate and ImageFilter (and may be others, I didn't test every function).

Is it a bug that ImageCorrelate and ImageFilter still affect alpha channel? If so, we should expect another code-breaking change in one of the future releases of Mathematica.

Or is it by design and we can rely on this functionality? If so, what is the logic behind this design decision? Currently I see no way to predict this behavior, and there is also no information in the Docs. Is there any method to know besides testing every function by hand?

(Cross-posted on Mathematica.SE.)

POSTED BY: Alexey Popkov
4 Replies
Posted 5 years ago

As for version 12.0.0, the described inconsistencies and the ImageCrop bug are still not resolved. :(

POSTED BY: Alexey Popkov
Posted 1 year ago

As for version 13.0.1, no progress so far... :(

POSTED BY: Alexey Popkov

At the moment I can just tell you that the issue is known and internal teams are looking into this. Please stay tuned for resolution. Thanks for bringing this up and taking the time to describe it.

POSTED BY: Vitaliy Kaurov
Posted 6 years ago

I can add that some basic functions seem to be simply confused by alpha channel. For example, ImageCrop can't crop:

img = Rasterize[
   Graphics[Rectangle[], PlotRange -> {{-2, 2}, {-2, 2}}, ImageSize -> 200], Background -> None]; 

ImageCrop[img] // Framed

image

One workaround is to temporarily set ColorSpace -> Automatic:

Image[ImageCrop[Image[img, ColorSpace -> Automatic]], ColorSpace -> "RGB"]

image

Dedicated thread: https://mathematica.stackexchange.com/q/20494/280

Reported to the support as [CASE:3968587].

POSTED BY: Alexey Popkov
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract