0

I'm writing an application that displays different color swatches to help people with color coordination. How can I find the RGB values of real world objects?

For example, one of the colors is Red Apple but obviously a red apple isn't just red. It has hints of other colors in it.

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
bedward
  • 3
  • 2

3 Answers3

0

For each object, I would do it this way:

  1. Use goolge images to search pictures of the object you want.
  2. Select the one that have the most accurate color, say, to your idea of a "red apple" for example.

--you can skip 1 and 2 if you have a digital picture of the object.

  1. Open that image in Paint; you can do it stroking the "Impr Pant" key on your keyboard, opening Paint, and then "ctrl+v" will paste the screenshoot in paint.
  2. Select the pick color tool on Paint (the one like a dropper) and click on the image, just in the place with the color you want.
  3. Select from the menu, "Colors -> Edit colors" and then in the Colors palette that opens, clic on "Define Custom Colors".
  4. You got it, there RGB values are at your right.

There must be an easier way, but this will work.

daniloquio
  • 3,822
  • 2
  • 36
  • 56
  • Google image might work but it will take me a very long time. Since I have learned some Java, I was hoping I could write a program to do it for me – bedward Sep 08 '11 at 22:12
  • I don't think that is a good idea given your purpose. [Note: My method gives me {Red Apple = RGB(158,28,36)}, but that will change a lot for a different person and different apple taste] – daniloquio Sep 08 '11 at 22:19
0

Well, it's not an easy task to be honest, but a good place to start would be with a digital camera and/or a flatbed scanner.

Once you have an image in the computer then the task is somewhat easier beacuse all you need is to use a picture / photo editing package such as photoshop or the gimp to sample a selection of colours before using them in your application.

once you have a few different samples, then you need to average them, and that's quite easy to do. Lets say you took 5 samples of RGB values:

    255,50,10
    250,40,11
    253,51,15
    248,60,13
    254,45,20

You simply need to add up each component and divide by how many samples you took so:

    Red = (255 + 250 + 253 + 248 + 254) / 5
    Green = (50 + 40 + 51 + 60 + 45) / 5
    Blue = (10 + 11 + 15 + 13 + 20) / 5

Now, if what your asking is how do I do this automatically in program code, that's a whole different kettle of fish, first you'll need something like a web cam, then you'll need to write code to capture images from the web-cam, then once you have your image you'll need not just the ability to pick colour, but to actually figure out where in the image the object you want to pick the colour from actually is.

For now, I'd look at using the first method, it's a bit manual I agree, but far easier and will get you started.

The image processing required to do the second maths has given software engineers & comp scientists headaches for years and is still not a perfect science... and that's before we even start thinking about the maths.

shawty
  • 5,729
  • 2
  • 37
  • 71
  • I have my webcam hooked up to my laptop but I just was hoping I could write an easy Java program to save the color values to a file. I was thinking something like holding the object in the middle of the frame and getting the color at the center – bedward Sep 08 '11 at 22:08
  • If it's so, take into account that the RGB values you will get from a picture will be very variable depending on light, position and camera settings. – daniloquio Sep 08 '11 at 22:13
  • I have to agree with daniloquio here, even in the same location it's going to be possible to get drastically differing variations in colour and light. If your using this for the purpose you mention, then you really do want to be trying 100% to get the same shade each time. – shawty Sep 08 '11 at 22:41
0

If your looking for a programmatic solution then you would look into bitwise operations. The general idea here is you would read the image in it's binary roots and then you could logically convert the bits into RGB values. There are several methods for doing this depending on programming language. Here is a method for Actionscript3.

http://www.flashandmath.com/intermediate/rgbs/explanations.html

also if your looking for the average color look here, (for AS3)

http://blog.soulwire.co.uk/code/actionscript-3/extract-average-colours-from-bitmapdata

a related method and explanation for Java

Bitwise version of finding RGB in java

Community
  • 1
  • 1
Chamilyan
  • 9,347
  • 10
  • 38
  • 67