Can we find which color is dominant in an image with using java,imagemagick or jmagick?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
This is a tricky problem. For example, if you have a small area of exactly the same colour and a large area of slightly different shades of a different colour then simply looking for the colour that is used the most is unlikely to give you result you want. You would get a better result by defining a set of colours and, for each, the ranges of RGB values that you consider to 'be' that colour.
This topic is discussed at length on the ImageMagick discourse server, for example: http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=12878
See also Fast way of getting the dominant color of an image
I just released a very simple algorithm that can be translated in Java trivially. It is called color-finder and works in JavaScript.
The proposed solutions in this thread can be thrown off by a few white characters in the image, whereas mine really tries to find the most prominent color, even if all the pixels aren't really exactly of the same color.
Here is a live demo.
Let me know if you find that useful.
In other way, we can done this job with Color Thief library. More information can be found here and here.
Credit to @svenwoltmann and @lokeshdhakar.
in java iterate on each pixel and determine color
Using plain java you can just iterate over each pixel and count how often each color is contained...
pseudo-code:
assuming your using additive color scheme, where (0,0,0) is black and (255, 255, 255) is white (correct me if i'm mistaken). Also, if you just want to find the dominant color out of RGB:
One idea I have, which any of you are free to scrutinize is to have 3 variables that each store one of the RGB values and add to each of them the appropriate value of every pixel in the image and then divide by (255*numOfPixels) to get a ratio of color. Then compare the 3 ratios: .60 for red and .5 for green would mean red is more dominant.
This is just an idea, and might need tweaking...