• Welcome to Vampyre Imaging Library Forum. Please login or sign up.
 

Color of an Image

Started by binfch, 25 July 2011, 19:22:02

Previous topic - Next topic

binfch

Hi there

I have 10 different RGB colors (example red, blue, green, etc...).

Now I need to read foto files (.jpg, .gif, .png) and decide to what preset color the images best fits to. Example -> let's supose on the foto there is a white cloud in the center surrounded by blue sky -> The result should then be the color "white". Or a black dog on a green lawn -> The result should be the color "black".

P.S: Google image search has such a functionality.

I was wondering how such a functionality could be implemented resp. what would be the most "performant" solution. An idea that comes to my mind is to simple resize the images to 3x3 pixel, then read the center pixel and decide what color is closest to it...

Thx & cheers,
Peter

Galfar

Hi,

resizing image and reading center pixel is a good idea but you can do it faster:
Resizing with filtering basically computes average color for certain area of pixels
bu also reallocates memory, uses fancy filters, etc. You can do the averaging manually, just read some
pixels from the area you're interested in and compute the average color.

To get it even faster don't sample every pixel, but say every 3rd (maybe depending on the size of source image). Also read the pixels directly using pointers when you know the images will be all be in the same data format (usually 24bit RGB) or in just few formats.

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Name:
Email:

Shortcuts: ALT+S save/post or ALT+P preview

SMF spam blocked by CleanTalk