Remove background using path.

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?".
Post Reply
groyk
Posts: 3
Joined: 2014-02-17T12:45:37-07:00
Authentication code: 6789

Remove background using path.

Post by groyk »

I have written following simple code in order to remove background on some images.

Code: Select all

convert test.tif -alpha transparent -clip -alpha opaque -strip test_tmp.tif
convert test_tmp.tif -background white  -alpha remove -resize 1600 -quality 85 result.jpg
On most images ImageMagick does not catch the path information correct.

Fail is located to first convert operaton.!

Please see image
Image

Clippath is tested and OK in Photoshop / Gimp / Scribus / Illustrater ect. with no failures

Anyone know what I am doing wrong?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Remove background using path.

Post by snibgo »

Please provide test.tif.
snibgo's IM pages: im.snibgo.com
groyk
Posts: 3
Joined: 2014-02-17T12:45:37-07:00
Authentication code: 6789

Re: Remove background using path.

Post by groyk »

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

Re: Remove background using path.

Post by snibgo »

identify -verbose test.tif shows the path. This includes "V" commands which should be followed by one or more y-coordinates but seems to be followed by (x,y) pairs. It also includes three "Y" commands. I can't find these in the SVG v1.1 specification. (http://www.w3.org/TR/SVG/paths.html)

So this looks like bad SVG, which different software will treat differently.
snibgo's IM pages: im.snibgo.com
groyk
Posts: 3
Joined: 2014-02-17T12:45:37-07:00
Authentication code: 6789

Re: Remove background using path.

Post by groyk »

I bleieve the Y's should be S's but I am not sure.

Anyway to change that in the tif file?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Remove background using path.

Post by snibgo »

In Gimp, you can edit the path at the bad points (towards top-left and bottom-right). With some fiddling, you can remove the bad "V" and "Y" commands. I don't know of an automated tool to do this.
snibgo's IM pages: im.snibgo.com
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Remove background using path.

Post by snibgo »

This problem is apparently cured by converting all the SVG "Y" and "V" commands to "L". Windows BAT script:

Code: Select all

call fixSvg test.tif

%IM%convert test.tif ( clipGood.svg -negate ) -alpha off -compose copy_opacity -composite t.png
... where fixSvg.bat is:

Code: Select all

rem From image file %1,
rem extract SVG and convert "V" and "Y" commands into "L".

%IM%identify -format %%[8BIM:1999,2998:#1] %1 > clipBad.svg

del clipGood.svg

for /F "tokens=1,*" %%A in (clipBad.svg) do (
  set COMMAND=%%A
  if "!COMMAND!"=="Y" set COMMAND=L
  if "!COMMAND!"=="V" set COMMAND=L
  echo !COMMAND! %%B>>clipGood.svg
)
See thread viewtopic.php?f=1&t=25594
snibgo's IM pages: im.snibgo.com
Post Reply