Page 1 of 1
Remove background using path.
Posted: 2014-02-17T13:09:41-07:00
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
Clippath is tested and OK in Photoshop / Gimp / Scribus / Illustrater ect. with no failures
Anyone know what I am doing wrong?
Re: Remove background using path.
Posted: 2014-02-17T13:36:21-07:00
by snibgo
Please provide test.tif.
Re: Remove background using path.
Posted: 2014-02-17T13:45:23-07:00
by groyk
Re: Remove background using path.
Posted: 2014-02-17T14:39:11-07:00
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.
Re: Remove background using path.
Posted: 2014-02-17T23:17:43-07:00
by groyk
I bleieve the Y's should be S's but I am not sure.
Anyway to change that in the tif file?
Re: Remove background using path.
Posted: 2014-02-18T01:52:10-07:00
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.
Re: Remove background using path.
Posted: 2014-05-19T10:48:37-07:00
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