Using kmeans script with transparent PNGs

A plethora of command-line scripts that perform geometric transforms, blurs, sharpens, edging, noise removal, and color manipulations.
Post Reply
fluxer
Posts: 5
Joined: 2015-09-18T22:12:06-07:00
Authentication code: 1151

Using kmeans script with transparent PNGs

Post 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.
Last edited by fluxer on 2015-10-18T10:45:10-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to separate transparent colors into different images

Post 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
fluxer
Posts: 5
Joined: 2015-09-18T22:12:06-07:00
Authentication code: 1151

Re: How to separate transparent colors into different images

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Using kmeans script with transparent PNGs

Post by fmw42 »

See my Private Mail to you on this forum.
Post Reply