Page 1 of 1
Using kmeans script with transparent PNGs
Posted: 2015-10-17T17:44:38-07:00
by fluxer
Hi,
I tried using this kmeans program, however I cannot seem to be able to input a PNG with a transparent background, and get out a PNG with a transparent background. I'm passing in the colors manually, and I've tried passing in "transparent", "none", "rgba(0,0,0,0)", to no avail. Any help would be appreciated.
Re: How to separate transparent colors into different images
Posted: 2015-10-17T18:02:20-07:00
by fmw42
I tried using this kmeans program, however I cannot seem to be able to input a PNG with a transparent background
Sorry, my kmeans script does not support transparent colors and thus no transparency in the input image.
The script document says:
# -s seedcolors ... SEEDCOLORS is a space delimited list of
opaque seed colors.
# It is used rather than just selecting a given number of colors. Providing a
# well selected list of colors can make the iteration process quicker. Any
# valid set of
opaque IM colors may be used. This includes rgb, hex or color
# names. However, there must not be any spaces in the color, especially for rgb
# color definitions. The default is to just use the desired number of colors.
In the future, please start a new topic. Always provide your IM version and platform. See
viewtopic.php?f=1&t=9620
If you have only a few colors including some transparent one, then you can separate them into new images one color per image using
Code: Select all
convert image.png -fuzz XX% -channel rgba -fill [i]somecolor[/i] +opaque "rgba(r,g,b,a)" output.png
where somecolor is whatever you want all other colors to be mapped to.
see
http://www.imagemagick.org/Usage/color_basics/#opaque
http://www.imagemagick.org/script/comma ... php#opaque
http://www.imagemagick.org/script/comma ... s.php#fuzz
Re: How to separate transparent colors into different images
Posted: 2015-10-18T10:44:14-07:00
by fluxer
Hi Fred,
I appreciate the help, and I'll be sure to create a new thread next time.
My IM version is: 6.8.7-7 Q16 x86_64 2014-09-02
If I were to make this its own topic, the title you set is not quite accurate. I am actually not looking for individual images per color, just a single image in and a single image out, with the colors limited to the set I specify, including fully transparent.
I was thinking of using your kmeans script in the following way:
- Apply a background color the input image
- Inputting that background color into kmeans as an -s argument, along with the other colors
- After completetion, making all pixels of that color transparent
The only issue is that I would have to calculate a background color that doesn't significantly influence the computation of the colors that are atop it (as in, no merging with the background), and I'm not sure how to make that calculation, especially in a computationally efficient way.
Re: Using kmeans script with transparent PNGs
Posted: 2015-10-18T11:45:37-07:00
by fmw42
See my Private Mail to you on this forum.