Page 2 of 2

Re: How to separate colors into different images

Posted: 2015-07-08T13:40:47-07:00
by fmw42
loskiroama wrote:Thanks for your suggestion snibgo, but it makes no difference.
May I know what is bq supposed to help me with?
bc does math calculations. You must re-install Cygwin and use the bc option in the install window.
loskiroama wrote:fmw42, Can I askyou how to call your modified script to get one image per color as you said?
It already has been modified as I mentioned earlier in this post.

Re: How to separate colors into different images

Posted: 2015-07-08T14:33:25-07:00
by loskiroama
You are absolutley right snibgo!
I installed bc and now I'm able to use different n parameters

The thing is that I'm getting a different color count using "identify -format %k" than the n that I entered.

For instance, this is the origial image
http://i.imgur.com/MXzRsyd.jpg
identify -format %k original.jpg
27397

And after excecuting "./kmeans -n 5 original.jpg out5.jpg" i get this
http://i.imgur.com/U9CXwd0.jpg
identify -format %k out5.jpg
10370

10370 is very different from 5 :(

After excecuting "./kmeans -n 2 original.jpg out2.jpg" i get this
http://i.imgur.com/ywc7Z7P.png
identify -format %k out2.jpg
3450

3450 is very different from 2 :(

What am I doing wrong?

Thanks again!

Re: How to separate colors into different images

Posted: 2015-07-08T14:39:12-07:00
by fmw42
Do NOT save the output to JPG, it is a lossy compression and will introduce many more colors. Save the output (with -f layered) to PNG if you want multiple images or TIFF if you want a layered image. If you want one image, then use -f flattened or leave that option off.

For example


kmeans -n 5 -C sRGB flower_blue2.jpg out.png
convert out.png -format "%k" info:
5

Re: How to separate colors into different images

Posted: 2015-07-10T06:26:11-07:00
by loskiroama
Wooow!!

Thank you so so much guys.
I'm so happy that imageMagick has such a great community of super smart and helpful people.
After your excellent instructions, I was able to separate colors into layers as I originally intended, but I'm facing another challenge now:

As you can see in the attached image the parts circled in red are causing me trouble because they present a very small (non-conex) area.
Is there any way that I could filter this small "islands".
http://i.imgur.com/n66hBzL.png
Maybe you could point me out where in the kmeans algorithm I could implement this filter,

Do you have any ideas?

Thanks once again. You rock :)

Re: How to separate colors into different images

Posted: 2015-07-10T09:15:54-07:00
by fmw42
You can try one of two approaches:

1) morphologic filtering such as

convert image -morphology close diamond:1 result

You can change the diamond shape to a square or to an octagon or define your own shapes. See http://www.imagemagick.org/Usage/morphology/


2) connected components labeling processing such as in http://www.imagemagick.org/script/conne ... onents.php to remove the smallest areas. You can choose the largest area you want to keep. The image needs to be binary. So you need to process the alpha channel of the individual image or layer.


However, if you filter those out, then you will have transparent holes in the image (or filled with some background color), if flattened later.

Re: How to separate colors into different images

Posted: 2015-07-11T14:54:16-07:00
by fmw42
I have added connected components labeling to remove small clusters to the script. See new examples on my kmeans page at the link below. It requires IM 6.8.9.10 or higher.