Anti-aliasing problem

(David) #1

Hello everyone,

I have a problem with gmic when I save photos with alpha channel.

Each time, the antialiasing is not clean. There are always black edges.

An example of commands :

gmic photo.jpg photo.jpg -transition3d 10,5,5 -output frame.png

gmic -input texture.jpg -text3d \ "G’MIC as a 3D logo! ", 53,10,1.5 -texturize3d [1] [0] -remove [0] -rotate3d [0] 0,1,0 , 45 -snapshot3d 500,1.5,0,0,0,0 -o text.png


Is this a program bug or did I miss something?

Thank you.

( #2

I do not have the same problem



Looks like anti-aliasing to me or at least the borders aren’t the right colour. It is better when I turn off the transparency using to_rgb. It is only apparent when you zoom in.

gmic sample tiger,tiger transition3d 10,5,5 keep[3] output test.png

gmic sample tiger,tiger transition3d 10,5,5 keep[3] to_rgb output test.jpg


Tyger Tyger, burning bright,
In the forests of the night;
What immortal hand or eye,
Could frame thy fearful symmetry?

In what distant deeps or skies,
Burnt the fire of thine eyes?
On what wings dare he aspire?
What the hand, dare seize the fire?

And what shoulder, & what art,
Could twist the sinews of thy heart?
And when thy heart began to beat,
What dread hand? & what dread feet?

What the hammer? what the chain,
In what furnace was thy brain?
What the anvil? what dread grasp,
Dare its deadly terrors clasp!

When the stars threw down their spears
And water’d heaven with their tears:
Did he smile his work to see?
Did he who made the Lamb make thee?

Tyger Tyger burning bright,
In the forests of the night:
What immortal hand or eye,
Dare frame thy fearful symmetry?

— William Blake

( #4

I alone anti-aliasing transparent

(David) #5

It looks like GMIC is not able to save a transparent image with normal anti-aliasing.

Try this other example: gmic -text3d “GMIC”,80,10,1.5 -snapshot3d 800,1,0,0,0,0 -o text.png

We see that the transparency of the edges is not progressive. Either it’s fully opaque, or it’s fully transparent (like an animated gif).

(David Tschumperlé) #6

This will be fixed in next version 2.3.0 (I’ll post binaries of the pre-release later today so you can test).

(David Tschumperlé) #7

That depends on how a particular filter does the rendering. Some filters allows anti-aliased rendering, other don’t. Transparent and anti-aliased are two different things. It is sometimes actually hard to render anti-aliased drawing correctly (this is the case for 3d objects).

(David) #8

Thank you David and congratulations for your work.

(David Tschumperlé) #9

More details about this problem:

The difficulty happens when a filter wants to render an anti-aliased object over a transparent background.
One usual way to do this is to rendering the drawing without anti-aliasing on an image with doubled resolution (2 x width , 2 x height), then downsize the resulting rendering back to the original image size, so each 2x2 neighborhood of the non-antialiased image is color-averaged to render the anti-aliased image.

So in practice, the anti-aliased result highly depends on the background color used for the doubled image. If background used was black, the pixels at the borders of the drawn object will be averaged with black (so anti-aliased parts looks darker). If background used is white, then anti-aliased parts will look brighter. Choosing a middle gray is not a solution either (anti-aliased pixels will look greyish).

One not-so-bad solution is to dilate the non-antialiased rendering a little bit before downsizing, so that coherent colors are duplicated near the neighborhood of the borders of the drawn object. When downsizing, averaging will be done with relatively correct colors.
This is just what I’ve done for the transition3d filter, and something equivalent should be done for other filters as well. I’ll see if I can automate this process easily.

But, as you see, this is not really as simple as it seems to be.

(David) #10

I do not have your level in programming but I am not sure that this is a good solution in long term?

For example, it is possible with other programs to obtain a good progressivity between the opacity of the image and the transparency during a perspective effect:

There is no other way to get a perfect antialing without “trick”?

(David Tschumperlé) #11

I don’t think so. And don’t be afraid image processing algorithms are usually full of tricks like this :wink: