Dithered Edges when converting from PNG to GIF, same problem
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Dithered Edges when converting from PNG to GIF, same problem
Without either color replacement or flood fill is tricky.
Basically you will need to determine what pixels are NOT involved in the anti-aliasing of the edges. Usually that is by floodfill or coor replacement.
If those are NOT posible, especially when involving background colors other than white or black, then you will need a masking method.
For that separate out a mask of the original image, ( -alpha extract ) and resize that
a -threshold 0 of that will then give you the transparency mask of the pixel not involved in anti-aliasing.
Now take the original image flatten it on white (or what ever background color), then resize it in the same way. Now if you re-add the thresholded mask, (using -compose CopyOpacity ) you make the pixels not involved in the anti-alising, transparent.
Here is the command (for a skyblue background)
This works, and should produce an image with a anti-aliased edge blending to a skyblue background. You can use whatever color you like.
NOTE: the threshold is 5% due to the way resize works. A smaller
value than this (unless a "Gaussian" or better still a "Mitchell " filter is enforced, can produce 'ringing effects'. This does not happen if transparency is present as IM would automatically switch to a "Mitchell" filter. For more infor see 'Ringing' Artifacts, in Im examples, Resize page.
Basically you will need to determine what pixels are NOT involved in the anti-aliasing of the edges. Usually that is by floodfill or coor replacement.
If those are NOT posible, especially when involving background colors other than white or black, then you will need a masking method.
For that separate out a mask of the original image, ( -alpha extract ) and resize that
a -threshold 0 of that will then give you the transparency mask of the pixel not involved in anti-aliasing.
Now take the original image flatten it on white (or what ever background color), then resize it in the same way. Now if you re-add the thresholded mask, (using -compose CopyOpacity ) you make the pixels not involved in the anti-alising, transparent.
Here is the command (for a skyblue background)
Code: Select all
convert orig2.png \
\( -clone 0 -background skyblue -flatten -resize 100x100 \) \
\( -clone 0 -alpha extract -resize 100x100 -threshold 5% \) \
-delete 0 -compose CopyOpacity -alpha off -composite \
result.gif
NOTE: the threshold is 5% due to the way resize works. A smaller
value than this (unless a "Gaussian" or better still a "Mitchell " filter is enforced, can produce 'ringing effects'. This does not happen if transparency is present as IM would automatically switch to a "Mitchell" filter. For more infor see 'Ringing' Artifacts, in Im examples, Resize page.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/