Some thoughts on antialiasing and clipping paths

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
jansuhr
Posts: 43
Joined: 2016-01-28T01:35:38-07:00
Authentication code: 1151

Some thoughts on antialiasing and clipping paths

Post by jansuhr »

I have some questions on this topic if it is possible.

An image with a clipping path needs to use the clipping path to get rid of the background outside of the path. I can do this with a few methods but I don't get the crips edges that Photoshop offers since there I can add anti-aliasing to the path when masking the background.

In IM we have -antialias but it is only working in combination with the -draw command.

So let's say I export the clipping path as an SVG-file.
Then add the SVG-file as a drawn shape where I add the antialias, will that work and can I set the line thickness to zero. Will it draw anyway?

When that path is there I can mask it and hopefully get a smother edge than the other methods give.

Would this be possible?

Thanks


Jan
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Some thoughts on antialiasing and clipping paths

Post by fmw42 »

Please, always provide your IM version and platform when asking questions, since syntax may differ. Also provide your exact command line and if possible your images.

See the top-most post in this forum "IMPORTANT: Please Read This FIRST Before Posting" at viewtopic.php?f=1&t=9620

For novices, see

viewtopic.php?f=1&t=9620
http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/
jansuhr
Posts: 43
Joined: 2016-01-28T01:35:38-07:00
Authentication code: 1151

Re: Some thoughts on antialiasing and clipping paths

Post by jansuhr »

Well, I don't consider this as a specific question but rather a thought on if this is even possible to achieve since I haven't found any good procedure on doing anti-aliasing on clipping paths. And in this case asking for IM versions or platforms is kind of secondary IMHO.

All of the so far suggested methods on this topic are not simply good enough.

The ones I have tried so far is mentioned here: viewtopic.php?f=1&t=29674&p=133783
or here in an earlier question by me: https://www.imagemagick.org/discourse-s ... =1&t=30711

Thanks

Jan
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Some thoughts on antialiasing and clipping paths

Post by fmw42 »

In the past, I have found that the following works better

Code: Select all

identify -quiet -format "%[8BIM:1999,2998:#1]" test.tif  |\
convert -quiet test.tif \( - -negate \) \
-alpha off -compose copy_opacity -composite \
-define tiff:alpha=associated \
result.tif
as opposed to

Code: Select all

convert -quiet test.tif -alpha transparent -clip -alpha opaque -strip result.tif

But you apparently have tried that and do not find it adequate. So I do not know what further to suggest.
jansuhr
Posts: 43
Joined: 2016-01-28T01:35:38-07:00
Authentication code: 1151

Re: Some thoughts on antialiasing and clipping paths

Post by jansuhr »

Yes I have tried both of them and it is a big difference between the result in IM and doing it in Photoshop with anti-aliasing.

The method you suggest is OK but the edges get blurred and are not as sharp as they are in Photoshop. And this gives a quality reduction in the images. The difference is very noticeable and will not be accepted. We are talking about high end fashion photography and thousand of images that has to get a transparent background as PSD and a white background as JPG.

So my question was if using the embedded path as an SVG that we can draw on the image and then apply the -antialias option to the SVG-path when it is being drawn on the image. What we would do here is to remake the clipping path to the image. If it gets anti-aliased during the SVG-drawing the then created mask from the drawn SVG might give a better and sharper edge to the image.

This is what I'm hoping for, but I haven't found anything like my thoughts here so either it is impossible or nobody have thought about it.


Thanks


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

Re: Some thoughts on antialiasing and clipping paths

Post by snibgo »

jansuhr wrote:...it is a big difference between the result in IM and doing it in Photoshop with anti-aliasing.
If you can post an example input file, and the outputs you get from Photoshop and IM, perhaps we can find what the difference is, and what to do about it.

Rasterizing an SVG should usually be antialiased. For some rasterizations, supersampling gives better results. I doubt f that is true here, but it might be.
snibgo's IM pages: im.snibgo.com
jansuhr
Posts: 43
Joined: 2016-01-28T01:35:38-07:00
Authentication code: 1151

Re: Some thoughts on antialiasing and clipping paths

Post by jansuhr »

Here is an example on the different results from this example:

Code: Select all

identify -quiet -format "%[8BIM:1999,2998:#1]" test.tif  |\
convert -quiet test.tif \( - -negate \) \
-alpha off -compose copy_opacity -composite \
-define tiff:alpha=associated \
result.tif
I have made the background white to show the effect better. As you can see there is a noticeable difference. The example below is at 100% zoom level and shows the jagginess that I get with IM.
Image


Here is the example file that I have used in this case.
https://dl.dropboxusercontent.com/u/687 ... front2.jpg


I'll be very happy if there is a way to solve this.

Thanks

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

Re: Some thoughts on antialiasing and clipping paths

Post by snibgo »

With IM v6.9.5-3 and Inkscape v0.91 on Windows 8.1, your command (adjusted for Windows) gives a smooth result, like your Photoshop result.
snibgo's IM pages: im.snibgo.com
jansuhr
Posts: 43
Joined: 2016-01-28T01:35:38-07:00
Authentication code: 1151

Re: Some thoughts on antialiasing and clipping paths

Post by jansuhr »

Ok, that's kind of positive but this has to work on both Mac and Windows.


Edit, I just saw that Inkscape is available for both plattforms. I haven't heard about Inkscape before :oops:


Thanks

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

Re: Some thoughts on antialiasing and clipping paths

Post by snibgo »

If Inkscape is on your Windows path, IM will use it to render SVG. I guess Mac is the same. Inkscape is available on most platforms.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Some thoughts on antialiasing and clipping paths

Post by fmw42 »

What is your IM version and platform? It works fine with your example image for me on IM 6.9.6.2 Q16 Mac OSX

Code: Select all

identify -quiet -format "%[8BIM:1999,2998:#1]" chevelle_70_front2.jpg  |\
convert -quiet chevelle_70_front2.jpg \( - -negate \) \
-alpha off -compose copy_opacity -composite \
-compose over -background white -flatten \
result1.tif
Here is a screen snap of a similar area:
Image
jansuhr
Posts: 43
Joined: 2016-01-28T01:35:38-07:00
Authentication code: 1151

Re: Some thoughts on antialiasing and clipping paths

Post by jansuhr »

I'm working on a plugin for a system that can work on both Windows and Mac. For the Windows version I can embed IM standalone but for Mac I haven't been able to create a working standalone version so in the case of Mac I will recommend the users to install IM via Brew, so that would be version 6.9 or something. If you check my post history you'll see my previous posts about compiling for Mac.

Myself I'm on Mac and IM version 6.9.2-10 Q16 x86_64 with OSX 10.10

I'll also testing on some Win-system running in virtual environment on my Mac.

I haven't yet installed Inkscape to run in Terminal yet. It needs some tweaking apparently reading on their webpage about it.

But it looks promising, for sure and I'm grateful for your tips :D

I will try this tomorrow.

Thanks


Jan
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Some thoughts on antialiasing and clipping paths

Post by fmw42 »

If it works on a current version of IM. Ask the Homebrew people (or MacPorts) to upgrade their IM version. MacPorts did that for me a while back with no complaints from them.
jansuhr
Posts: 43
Joined: 2016-01-28T01:35:38-07:00
Authentication code: 1151

Re: Some thoughts on antialiasing and clipping paths

Post by jansuhr »

Ok I have tried this now in Windows and it seems to work except that the resulting image is negative.

I guess it has something to do with the ( - -negate ) part of the command. I have never been able to have the ( ) work in the command line, not with \( \) either.


If I after the process run just the -negate command it will find the path through Inkscape and sort of remove the part of the image I want.


Thanks


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

Re: Some thoughts on antialiasing and clipping paths

Post by snibgo »

I have never been able to have the ( ) work in the command line, not with \( \) either.
Parentheses are an important part of this command, and many others. On Windows, the escape character is the caret, ^. Hence if they need to be escaped use ^( and ^).
snibgo's IM pages: im.snibgo.com
Post Reply