Page 1 of 1

how I could use kmeans in this image and obbtain the hair blonde color ?

Posted: 2018-08-12T10:45:34-07:00
by diegomage
IM trying to convert elsa image but the blonde color in the image when I use kmeans

I use kmeans from this page
http://www.fmwconcepts.com/imagemagick/kmeans/index.php

Code: Select all

 ./kmeans elsa.png kdf_black2.png -n 15 -C LAB 

not works to get the color of hair and differentiate for skin pink color


INPUT IMAGE

Image

RESULT IMAGE
Image


please help me

Re: how I could use kmeans in this image and obbtain the hair blonde color ?

Posted: 2018-08-12T11:08:08-07:00
by fmw42
Try using seed colors in the script rather than just some number of colors. But I doubt that will work. You can also try -remap. See https://www.imagemagick.org/Usage/quantize/#remap

Re: how I could use kmeans in this image and obbtain the hair blonde color ?

Posted: 2018-08-12T11:46:09-07:00
by diegomage
yes very thankyou I try but not get results .

Re: how I could use kmeans in this image and obbtain the hair blonde color ?

Posted: 2018-08-12T11:51:25-07:00
by fmw42
I do not know how to help. Your input image is rather poor.

Re: how I could use kmeans in this image and obbtain the hair blonde color ?

Posted: 2018-08-12T17:20:23-07:00
by diegomage
I use kmeans for obtain the most common color and use a mask over each color and use a kmeans over each color mask of original image and combine all parts , repeating my code 5 times and works
this is my code

Code: Select all

 ./kmeans anna2.jpg kdf_black2.png -n 15  -colors 15  -c 0.3 -C sRGB -t flattened  >colorsf
convert anna2.jpg    -fuzz 100% -fill white -opaque black annafinal3.png
convert   annafinal3.png   -transparent white  annafinal3.png 

n=3

echo $n;n=$(($n + 1));p="p";vartt=$n$p;vartx=$(sed -n "$vartt" <colorsf);echo $vartx;echo $vartx > filevartx;x=$(grep  -Po '[^,]+$' filevartx);convert kdf_black2.png  -fill white +opaque "$x"  kdf_black3.png
convert kdf_black3.png  -fill black -opaque "$x"   kdf_black4.png;convert kdf_black4.png -negate kdf_black4x.png; convert anna2.jpg  -mask kdf_black4x.png         -fuzz 90% -fill white -opaque black  +mask kdf_black5.png
 ./kmeans  kdf_black5.png kdf_black2x.png -n 15  -colors 15  -c 0.3 -C sRGB -t flattened 
convert  kdf_black2x.png  -transparent white "annafinal$n.png"
z=$(($n - 1))
composite  "annafinal$z.png"  "annafinal$n.png"   "annafinal$n.png"
this is my result

Image

very thankyou