I want to create a program that determines all the areas of a given picture that have a different color, or the same color with different luminosities.

Are there known algorithms that do this job ? I would love to study such algorithms and implement them.

Thank you in advance for any help.

  • 1
    \$\begingroup\$ It might be worth converting the image into YCrCb and discarding the Luma component \$\endgroup\$
    – OMGtechy
    Jan 19, 2015 at 21:11
  • 2
    \$\begingroup\$ This is a big topic with lots of kinds of answers. You can make a histogram of brightness for all the pixels. But to decompose the 2d structure of the image, terms like feature extraction, boundary detection, flood-fill, and posterization may provide some starting points... \$\endgroup\$ Jan 19, 2015 at 21:22
  • \$\begingroup\$ I think this is too broad. You can start by what @david suggested. Otherwise try to reduce the scope of the question, for example, why do you want to do this ? maybe this is not the solution you want. Maybe if you tell us more we can give you better answers, so far I suspect the answers to be generic. \$\endgroup\$
    – concept3d
    Jan 20, 2015 at 10:15
  • \$\begingroup\$ @concept3d Thank you for the advice. I thought my question is clear, but I will edit it in few hours. Regards \$\endgroup\$
    – user59526
    Jan 20, 2015 at 10:44

2 Answers 2


I've been researching Sobel Filters for edge detection. I then use that information to identify bounding information so I can crop out borders programmatically.

I also like OMGtechy's comment on converting to YCrCb or YUV and throwing out the Luma component. MSDN has an article on RGB to YUV Strangely enough, looks like it's HLSL (shader).

  • \$\begingroup\$ I hadn't heard of those filters, interesting. \$\endgroup\$
    – OMGtechy
    Jan 20, 2015 at 21:24

One possible approach is this:

  1. Convert to the YCrCb colour space and discard the Luma (Y) component.
  2. Compute a quality metric (see below),
  3. See if the quality metric is above a threshold (see below),

Quality Metrics

  • ASNR
  • PSNR
  • SSIM


This will be largely trial and error; you'll just have to tweak it until you get the results you want. I'd start at about 50 for PSNR/ASNR, or 0.9 for SSIM and work from there.

  • \$\begingroup\$ @Begueradj if you're happy with the answer, please accept it when you can. Otherwise, suggest improvements and I'll do my best to make them. Please note that problems with specific implementations are separate questions and should not be included in the answer to this one (although I may link them at a later date if people find this useful). \$\endgroup\$
    – OMGtechy
    Jan 19, 2015 at 21:26

You must log in to answer this question.