disable antialiasig for rotation and MagickAppendImages with overlapping

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
bayek
Posts: 6
Joined: 2017-01-01T12:57:30-07:00
Authentication code: 1151

disable antialiasig for rotation and MagickAppendImages with overlapping

Post by bayek » 2017-01-01T13:34:09-07:00

Hi,
I have two questions
1. How can I disable antialiasing for MagickRotateImage(wand, background, degrees) ?
The image contains thin black contours more suitable for vector format. Background pixel wand is transparent. Rotation with imagemagick adds antialiasing pixels around the contours. Is it possible to have the result in exact the same colour, without any antialiasing? I understand that there will be jagged edges, it does not matter.

2. Is it possible to make MagickAppendImages do partial overlapping of the images? Preferably with configurable overlapping for each image in the sequence.

snibgo
Posts: 9378
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: disable antialiasig for rotation and MagickAppendImages with overlapping

Post by snibgo » 2017-01-01T15:15:57-07:00

1. I'm not sure exactly what you want. If you have an image that is black and white only, and rotate it, the result will also contain shades of gray.

I don't think there is any way to prevent this. Using "-distort SRT" with one of the filters such as box or point might have done this, but it doesn't seem to.

Working at a lower level, calling the functions, might offer an alternative. I don't know.

Another possibility is simply to threshold after the rotation.


2. MagickSmushImages() seems a better choice, as smush is effectively "append with positive or negative gap". See http://www.imagemagick.org/script/comma ... .php#smush and viewtopic.php?f=1&t=30720
snibgo's IM pages: im.snibgo.com

bayek
Posts: 6
Joined: 2017-01-01T12:57:30-07:00
Authentication code: 1151

Re: disable antialiasig for rotation and MagickAppendImages with overlapping

Post by bayek » 2017-01-01T15:56:59-07:00

smush crashes on the same wand append works with without errors, with "MagickWand/magick-image.c:10542: MagickSetImageType: Assertion `wand != (MagickWand *) NULL' failed."

Code: Select all

MagickAppendImages(mw, MagickFalse); //ok
//MagickSmushImages(mw, MagickFalse, 0.0); //crash

User avatar
fmw42
Posts: 22079
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: disable antialiasig for rotation and MagickAppendImages with overlapping

Post by fmw42 » 2017-01-01T16:12:54-07:00

What is your IM version and Platform? Perhaps you need to upgrade your IM to the current version to get smush to work? It will give partial overlap, for which append will not.

bayek
Posts: 6
Joined: 2017-01-01T12:57:30-07:00
Authentication code: 1151

Re: disable antialiasig for rotation and MagickAppendImages with overlapping

Post by bayek » 2017-01-01T16:32:20-07:00

Linux gentoo x64, Imagemagick 7, built from github
git clone http://git.imagemagick.org/repos/ImageMagick

Code: Select all

Version: ImageMagick 7.0.4-2 Q16 x86_64 2017-01-01 http://www.imagemagick.org
Copyright: © 1999-2017 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC HDRI 
Delegates (built-in): png 


snibgo
Posts: 9378
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: disable antialiasig for rotation and MagickAppendImages with overlapping

Post by snibgo » 2017-01-01T17:13:48-07:00

bayek wrote:"MagickWand/magick-image.c:10542: MagickSetImageType: Assertion `wand != (MagickWand *) NULL' failed."
So the failure is in function MagickSetImageType(). As far as I can see, MagickSmushImages() doesn't call that function. So something else in your code calls it, directly or indirectly.

Does your code correctly check for errors, or does it ignore them? Where, in your code, does the MagickSetImageType() failure occur?
snibgo's IM pages: im.snibgo.com

bayek
Posts: 6
Joined: 2017-01-01T12:57:30-07:00
Authentication code: 1151

Re: disable antialiasig for rotation and MagickAppendImages with overlapping

Post by bayek » 2017-01-02T01:00:22-07:00

Yes you are right, smush just returns NULL, so the next line crashes.
The code looks like that:

Code: Select all

mwcombined = MagickSmushImages(mw, MagickFalse, 0.0);
MagickSetImageType(mwcombined, PaletteAlphaType);

bayek
Posts: 6
Joined: 2017-01-01T12:57:30-07:00
Authentication code: 1151

Re: disable antialiasig for rotation and MagickAppendImages with overlapping

Post by bayek » 2017-01-02T03:32:40-07:00

also I don't understand another thing
MagickOpaquePaintImage

MagickOpaquePaintImage() changes any pixel that matches color with the color defined by fill.

Code: Select all

    MagickSetImageType(mwcombined, GrayscaleAlphaType);
    MagickWriteImage(mwcombined,"1.png");

    pwwhite = NewPixelWand();
    PixelSetColor(pwwhite,"white");

    pwtransparent = NewPixelWand();
    PixelSetColor(pwtransparent,"none");

    MagickOpaquePaintImage(mwcombined, pwwhite, pwtransparent, 100, MagickFalse);

    MagickWriteImage(mwcombined,"2.png");


this code is supposed to change white parts of the mwcombined to transparent, but it doesn't do this. It does something other though, as the image size gets changed, but there are no visible changes. Different values of fuzz change nothig.


http://i.cubeupload.com/F7jU0J.png - 1.png
http://i.cubeupload.com/uF8GQd.png - 2.png

both images have white line at the bottom and black/transparent above, it can be seen in gimp bettern than in browser.

snibgo
Posts: 9378
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: disable antialiasig for rotation and MagickAppendImages with overlapping

Post by snibgo » 2017-01-02T03:54:16-07:00

You want to change pixels to be transparent, but you are using MagickOpaquePaintImage()? Have you tried MagickTransparentPaintImage()?
snibgo's IM pages: im.snibgo.com

bayek
Posts: 6
Joined: 2017-01-01T12:57:30-07:00
Authentication code: 1151

Re: disable antialiasig for rotation and MagickAppendImages with overlapping

Post by bayek » 2017-01-02T04:23:18-07:00

MagickTransparentPaintImage changes nothing. But I found that if I use MagickTrue as the last parameter (invert) of the MagickTransparentPaintImage, it makes all the image transparent. So apparently it just does not think that color of the target matches color of the image which should be replaced. I tried both "white" and "#fefefe" (the exact lolour from colorpicker in gimp) http://i.cubeupload.com/uF8GQd.png, but it does not match the colour in any of combination of the parameters.

And I don't understand why MagickSmushImages returns NULL.

Post Reply