Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 721549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:53:10+00:00 2026-05-14T05:53:10+00:00

I would like to check what colors is present in a image. This will

  • 0

I would like to check what colors is present in a image. This will be stored in the database and used for a search form. (red=1, green=1, blue=0, yellow=1, black=1, white=1 etc.)

img = Magick::Image.read('phosto-file.jpg').first
img = img.quantize(10
h = img.color_histogram
pp h
{red=12815, green=18494, blue=15439, opacity=0=>13007,
 red=44662, green=47670, blue=51967, opacity=0=>18254,
 red=17608, green=43331, blue=48321, opacity=0=>11597,
 red=21105, green=25865, blue=39467, opacity=0=>10604,
 red=15125, green=36629, blue=22824, opacity=0=>10223,
 red=52102, green=42405, blue=10063, opacity=0=>12928,
 red=39043, green=28726, blue=40855, opacity=0=>7728,
 red=10410, green=8880, blue=7826, opacity=0=>13795,
 red=25484, green=25337, blue=24235, opacity=0=>7351,
 red=44485, green=12617, blue=11169, opacity=0=>14513}

How do I convert the 10 values to color names? red, green, NOMATCH, yellow, black, white etc. Only need the rough color name – not LimeGreen but Green etc.

Best regards.
Asbjørn Morell

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T05:53:10+00:00Added an answer on May 14, 2026 at 5:53 am

    If you could represent all of the colors you are looking for in the same number format that ImageMagick returns. Then you could compare the RGB values to find which it is closest to.

    So for instance if you have a histogram value of (assuming 255 values for each color, YMMV)

    { red => 10, green => 255, blue => 10 }
    

    Then you could compare it to each of

    {
      red   => {red => 255, green => 0, blue => 0},
      green => {red => 0, green => 255, blue => 0},
      blue  => {red => 0, green => 0, blue => 255}
    }
    

    So if you add up the difference between all of the elements you’ll get

    {
      red   => 510,
      green =>  20,
      blue  => 510,
    }
    

    So you can clearly see that the color is closest to green

    UPDATE: Added a solution in Ruby

    
    def compare_color(color_val)
      colors = {
        :red    => [255,0,0],
        :green  => [0,255,0],
        :blue   => [0,0,255]
      }
    
      difference = {}
    
      def compare_array(a1,a2)
        total = 0
        a1.each_index do |x|
          total += (a1[x]-a2[x]).abs
        end
        total
      end
    
      colors.each do |color,hex|
        difference[color] = compare_array(color_val,hex)
      end
    
      closest = difference.sort{|a,b| a[1]  b[1]}.first                                                                       [closest,difference]
    end
    
    p compare_color([10,255,10])
    # [[:green, 20], {:red=>510, :green=>20, :blue=>510}]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to search a text in xml file and check that it
I would like to check which type of RAM my computer uses before I
I would like to check my JavaScript files without going to JSLint web site.
I would like to check whether an object (e.g. someObject ) is assignable (cast-able)
I would like to check if a few URL's exst on my old website
I would like to check whether the request is XML od HTML. When HTML
I would like to check if an object is defined or exists using C#.
I would like to check the memory consumption of each running processes individually, cat
We would like to check if a specified process is currently running via PHP.
I would like to check that I have workingDir = C:\Users\~\Temp\workspace_folder; for i=1:2 %

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.