Convert png to vectors
Convert png to vectors
Is it possible to convert png to vectors? I have big file: 15392x11189px. The're four colors there: #483d8b (dark blue), #d02090 (purple), #ab2cb3 (pink) and gray #cccccc. In photoshop there is possibility to select color with some tolerance, there is limit from 0 to 200 and I used 82 to select. I tried to covert it to vectors.. shapes in four layers but did not succeed, Can anybody help me with this please? Some code to get the three colors to separate layers, to be used in photoshop. Maybe it could be exported to four files in EPS or some commpon format for vectors.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Convert png to vectors
The color tolerance in Imagemagick is called 'fuzz'
http://www.imagemagick.org/Usage/color_basics/#fuzz
You can seperate the four colors in a couple of different ways. This saves each color as a white on black mask.
If you need these colors in a vector format. I suggest you run the original image through something like "autotrace".
If the autotrace library is installed when IM is compiled, IM will atomatically generate a true vector image when you save to SVG image file format. If it is not the SVG image is made of a lot of circles (one circle per image).
See these sections of IM Examples
http://www.imagemagick.org/Usage/draw/#svg_output
http://www.imagemagick.org/Usage/transform/#edge_vector
And the new example (for skeletion generation) at
http://www.imagemagick.org/Usage/morpho ... e_skeleton
autotrace can handle color images, but as with all raster-to-vector convertors only works properly when the number of colors is limited, and it assumes you are starting with a white background (you may need to negate the above masking images to vectorize the colors separately)
If you want more help give us a small example image!
http://www.imagemagick.org/Usage/color_basics/#fuzz
You can seperate the four colors in a couple of different ways. This saves each color as a white on black mask.
Code: Select all
convert image_in \
\( +clone -fill white -opaque '#483d8b' -fill black +opaque '#483d8b' -write dark_blue.png +delete \) \
\( +clone -fill white -opaque '#d02090' -fill black +opaque '#d02090' -write purple.png +delete \) \
\( +clone -fill white -opaque '#ab2cb3' -fill black +opaque '#ab2cb3' -write pink.png +delete \) \
\( +clone -fill white -opaque '#cccccc' -fill black +opaque '#cccccc' -write gray.png +delete \) \
null:
If the autotrace library is installed when IM is compiled, IM will atomatically generate a true vector image when you save to SVG image file format. If it is not the SVG image is made of a lot of circles (one circle per image).
See these sections of IM Examples
http://www.imagemagick.org/Usage/draw/#svg_output
http://www.imagemagick.org/Usage/transform/#edge_vector
And the new example (for skeletion generation) at
http://www.imagemagick.org/Usage/morpho ... e_skeleton
autotrace can handle color images, but as with all raster-to-vector convertors only works properly when the number of colors is limited, and it assumes you are starting with a white background (you may need to negate the above masking images to vectorize the colors separately)
If you want more help give us a small example image!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: Convert png to vectors
I got the png from this pdf document http://www.aecr.cz/download.php?file=up ... stavba.pdf by convertion to png. If I would have the svg file I would not know how to open it in Photoshop.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Convert png to vectors
Auto trace can generate a lot of different vector formats from a raster image, not just SVG.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Convert png to vectors
Note converting this PDF image to a raster image, to seperate, then back to vector is probably not the ideal method. Especially as some colors overlap, and the raster image is not pure colors but will have a LOT of anti-aliases color shades.
If you images are comming from a specific source. The better idea may be to modify that source to produce one 'layer' of the output at a time. OR parse the output and try to use that to separate your layers.
In other words. look for a vector solution. IM is unlikely to produce a good solution, except in the form of a raster mask for the vector image, and even that is iffy!
If you images are comming from a specific source. The better idea may be to modify that source to produce one 'layer' of the output at a time. OR parse the output and try to use that to separate your layers.
In other words. look for a vector solution. IM is unlikely to produce a good solution, except in the form of a raster mask for the vector image, and even that is iffy!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: Convert png to vectors
I tried this to test:
Returns convert.exe: unrecognized color `'#483d8b'' @ warning/color.c/GetColorCompliance
/947.
What do I do wrong?
PS: Am not sure If I understand your last post completely. And how can I test if I have autotrace installed
Code: Select all
convert test_CR.png -fuzz 40% -fill red -opaque '#483d8b' test.png
/947.
What do I do wrong?
PS: Am not sure If I understand your last post completely. And how can I test if I have autotrace installed
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Convert png to vectors
Are you using DOS? You never said. Change sigle quotes to double quotes.
See Using Imagemagick with Windows.
http://www.imagemagick.org/Usage/windows/#dos
Also for windows you may need to downlaod and add autotrace yourself, as I doubt it is installed by default!
autotrace is a seperate delegate library. It can be used separateally to ImageMagick.
http://autotrace.sourceforge.net/
See Using Imagemagick with Windows.
http://www.imagemagick.org/Usage/windows/#dos
Also for windows you may need to downlaod and add autotrace yourself, as I doubt it is installed by default!
autotrace is a seperate delegate library. It can be used separateally to ImageMagick.
http://autotrace.sourceforge.net/
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: Convert png to vectors
Yes I use DOS, I will check it later, today I need to sleep. Thanks
Re: Convert png to vectors
There is no working link for autotrace for Windows download.
Last edited by VanGog on 2012-03-19T04:32:40-07:00, edited 1 time in total.
Re: Convert png to vectors
OK I got the modul from Softpedia, but I cannot find information how to install. There is readme but missing the INSTALL section and INSTALL file not in the archive.
Where should I place autotrace modul, Under ImageMagick\plugins or anywhere? I must to edit path to this program probably, should I set some global variable to its path? Thanks for advice
Where should I place autotrace modul, Under ImageMagick\plugins or anywhere? I must to edit path to this program probably, should I set some global variable to its path? Thanks for advice
Re: Convert png to vectors
If you could not help me with autotrace, maybe you could help me with the DOS command
To remake it to save the "masks" in four grayscale files gif or png. Actually the colored png is very big file and the Photoshop is stuck totally to work with it. If you could to advice to export it to images with 2 colors, I could try to convert it to vectors by photoshop...
Code: Select all
convert test_CR.png ^
( +clone -fill white -opaque "#483d8b" -fill black +opaque "#483d8b" -write dark_blue.png +delete ) ^
( +clone -fill white -opaque "#d02090" -fill black +opaque "#d02090" -write purple.png +delete ) ^
( +clone -fill white -opaque "#ab2cb3" -fill black +opaque "#ab2cb3" -write pink.png +delete ) ^
( +clone -fill white -opaque "#cccccc" -fill black +opaque "#cccccc" -write gray.png +delete ) ^
null:
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Convert png to vectors
convert test_CR.png ^
( +clone -fill white -opaque "#483d8b" -fill black +opaque "#483d8b" -write dark_blue.png +delete ) ^
( +clone -fill white -opaque "#d02090" -fill black +opaque "#d02090" -write purple.png +delete ) ^
( +clone -fill white -opaque "#ab2cb3" -fill black +opaque "#ab2cb3" -write pink.png +delete ) ^
( +clone -fill white -opaque "#cccccc" -fill black +opaque "#cccccc" -write gray.png +delete ) ^
null:
Your command looks OK to me. But you don't need the +delete if you change +clone to -clone 0. The null: at the end will delete all images but the ones you explicitly created using -write. You may also need to add a -fuzz XX% to your command if you do not have exactly those colors but have some nearby.
Re: Convert png to vectors
That is the code from anthony. I only edited it to DOS.
Can you please test it with this image?
http://www.crocko.com/564312B9382A40428 ... est_CR.png
Click bottom right and wait 2 minutes till start the download
It is 64kB and I got four files with 1kB size - nothing there. Does not work to me.
THX
Can you please test it with this image?
http://www.crocko.com/564312B9382A40428 ... est_CR.png
Click bottom right and wait 2 minutes till start the download
It is 64kB and I got four files with 1kB size - nothing there. Does not work to me.
Code: Select all
convert test_CR.png ^
( +clone -fuzz 50% -fill white -opaque "#483d8b" -fill black +opaque "#483d8b" -write dark_blue.png +delete ) ^
( +clone -fuzz 50% -fill white -opaque "#d02090" -fill black +opaque "#d02090" -write purple.png +delete ) ^
( +clone -fuzz 50% -fill white -opaque "#ab2cb3" -fill black +opaque "#ab2cb3" -write pink.png +delete ) ^
( +clone -fuzz 50% -fill white -opaque "#cccccc" -fill black +opaque "#cccccc" -write gray.png +delete ) ^
null:
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Convert png to vectors
Several problem.
1) your hex colors are not precise enough (see your histogram from the verbose info)
identify -verbose yourimage
2) you have an alpha channel that is best to turn off so that you don't have to the alpha channel in your hex values
3) and biggest issue is you have to specify the +opaque before the -opaque or else the +opaque value will no longer exists.
So in unix this works for me, though you may want to have a fuzz value included to get more similar colored pixels.
convert 1test_CR.png -alpha off \
\( +clone -fill black +opaque '#483D8B' -fill white -opaque '#483D8B' -write 1dark_blue.png +delete \) \
\( +clone -fill black +opaque '#AB2CB3' -fill white -opaque '#AB2CB3' -write 1purple.png +delete \) \
\( +clone -fill black +opaque '#D02090' -fill white -opaque '#D02090' -write 1pink.png +delete \) \
\( +clone -fill black +opaque '#CCCCCC' -fill white -opaque '#CCCCCC' -write 1gray.png +delete \) \
null:
For Windows, remove the \ escape for the parens, use ^ rather than \ for end of line and change single quotes to double quotes
1) your hex colors are not precise enough (see your histogram from the verbose info)
identify -verbose yourimage
2) you have an alpha channel that is best to turn off so that you don't have to the alpha channel in your hex values
3) and biggest issue is you have to specify the +opaque before the -opaque or else the +opaque value will no longer exists.
So in unix this works for me, though you may want to have a fuzz value included to get more similar colored pixels.
convert 1test_CR.png -alpha off \
\( +clone -fill black +opaque '#483D8B' -fill white -opaque '#483D8B' -write 1dark_blue.png +delete \) \
\( +clone -fill black +opaque '#AB2CB3' -fill white -opaque '#AB2CB3' -write 1purple.png +delete \) \
\( +clone -fill black +opaque '#D02090' -fill white -opaque '#D02090' -write 1pink.png +delete \) \
\( +clone -fill black +opaque '#CCCCCC' -fill white -opaque '#CCCCCC' -write 1gray.png +delete \) \
null:
For Windows, remove the \ escape for the parens, use ^ rather than \ for end of line and change single quotes to double quotes
Re: Convert png to vectors
Thanks a lot. I don't understand where you find the information that the colors are not precise and the alpha channel present (?).
When I write the command, I got this error:
convert.exe: unrecognized color `'#483D8B'' @ warning/color.c/GetColorCompliance /947.
convert.exe: unrecognized color `'#AB2CB3'' @ warning/color.c/GetColorCompliance /947.
convert.exe: unrecognized color `'#D02090'' @ warning/color.c/GetColorCompliance /947.
convert.exe: unrecognized color `'#CCCCCC'' @ warning/color.c/GetColorCompliance /947.
Do I use the fuzz right?
+clone -fuzz 50% -fill ....
When I write the command, I got this error:
convert.exe: unrecognized color `'#483D8B'' @ warning/color.c/GetColorCompliance /947.
convert.exe: unrecognized color `'#AB2CB3'' @ warning/color.c/GetColorCompliance /947.
convert.exe: unrecognized color `'#D02090'' @ warning/color.c/GetColorCompliance /947.
convert.exe: unrecognized color `'#CCCCCC'' @ warning/color.c/GetColorCompliance /947.
Do I use the fuzz right?
+clone -fuzz 50% -fill ....