Results 1 to 9 of 9

Thread: (VB6) Get the main or prevalent color tone of a picture

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,997

    (VB6) Get the main or prevalent color tone of a picture

    Some applications set a background color (or even other "theme" colors) based on an image that the user selects.

    That's the idea, to get the main color tone of an image.

    Name:  Get-Image-Main-Tone-scr1.jpg
Views: 743
Size:  21.6 KB

    Name:  Get-Image-Main-Tone-scr2.jpg
Views: 665
Size:  58.1 KB

    Name:  Get-Image-Main-Tone-scr3.jpg
Views: 700
Size:  53.7 KB


    Download from GitHub.

  2. #2
    Hyperactive Member
    Join Date
    Dec 2008
    Location
    Argentina
    Posts
    439

    Re: (VB6) Get the main or prevalent color tone of a picture

    Exelent Eduardo!!
    leandroascierto.com Visual Basic 6 projects

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,997

    Re: (VB6) Get the main or prevalent color tone of a picture

    Thanks Lea

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,997

    Re: (VB6) Get the main or prevalent color tone of a picture

    Updated. I added another function IsDarkColor to be able to easily choose the ForeColor according the the BackColor.

  5. #5
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    673

    Re: (VB6) Get the main or prevalent color tone of a picture

    good idea.I think it can be used to identify image similarity.

  6. #6
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: (VB6) Get the main or prevalent color tone of a picture

    What is the "main" color? It can't be the average color based on just looking at those samples.

    "Most common color" (histogram) gets dicey when JPEGs and photos in general are used.

    I'm not sure "dark color" tests help much. What if the BackColor is something close to &H00808080 gray?

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,997

    Re: (VB6) Get the main or prevalent color tone of a picture

    Quote Originally Posted by dilettante View Post
    What is the "main" color? It can't be the average color based on just looking at those samples.
    I'll try to explain the algorithm simply:

    If the image is too large, reduce it.
    Scan all pixels and convert them to HLS colors.
    (HLS consist on three values for each pixel. All three go from 0 to 239. H is Hue, S is Saturation and L is Luminance or Lightness).
    There is a vector of 240 variables, each one for each Hue.
    Sum a value to the corresponding variable in the vector every time the corresponding Hue appear in the image. It is not just +1, but a value that takes into account the saturation and the Luminance of the pixel color also.
    Then we have the color spectrum of 240 tones (Hue), with the values for each one.
    But there is also another array, of 6 color zones.
    In this array this 240 colors are grouped into 6 "zones". The first zone is from 0-39 Hue values, from 40 to 79 zone 2, from 80 to 119 zone 3, etc.
    We first look what zone has more values, and as a second refinement we look what color tone in that zone has most value.

    Why first to find the zone and secondly the exact color?
    Suppose that one particular color, for example a yellow is the one that has more pixels, but between the range of blues we have more in total the image, but individually none of the blues surpass this only one yellow. We want a blue as the resulting main color, not the yellow. That's the idea.

    Where did I get this from? From nowhere. I don't know if it is the best method, but it seems to work. This is not for NASA.

    Quote Originally Posted by dilettante View Post
    "Most common color" (histogram) gets dicey when JPEGs and photos in general are used.

    I'm not sure "dark color" tests help much. What if the BackColor is something close to &H00808080 gray?
    As explained above, grays won't be taken into account. A few colored pixels in a black and white image could set the main tone.
    I didn't test it much, it worked with many images that it tested but it needs more testing.

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,997

    Re: (VB6) Get the main or prevalent color tone of a picture

    Quote Originally Posted by xxdoc123 View Post
    good idea.I think it can be used to identify image similarity.
    Humm, I don't think it could be used to find similar images, that is interesting but entirely something different, and certainly much more complex.

    I saw that there are programs that can find "same" images even when they are resized or have some minor differences, but I currently have no idea what kind of algorithm they use.

    Well, that would be a matter of study.
    https://medium.com/@gabriel_83172/ho...l-67f3c987b643
    https://stackoverflow.com/questions/...similar-images
    https://stackoverflow.com/questions/...ages-algorithm
    https://stackoverflow.com/questions/...rom-a-database

    Also face recognition would be interesting but it is hard to work on these fields if there is no money to support the projects.

  9. #9
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: (VB6) Get the main or prevalent color tone of a picture

    It does seem to be effective.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width