Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Urgent - How to identify given image is too dark or light

Urgent - How to identify given image is too dark or light

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
11 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S sujtha

    How to identify given image is too dark or light? Input format of the file is tif and jpg.

    W Offline
    W Offline
    Waldermort
    wrote on last edited by
    #2

    By taking a look at it I suppose... Please don't mark your topic with the word Urgent.

    Waldermort

    T 1 Reply Last reply
    0
    • S sujtha

      How to identify given image is too dark or light? Input format of the file is tif and jpg.

      R Offline
      R Offline
      Russell
      wrote on last edited by
      #3

      images are made of pixel, then every pixel has got a color, the color is a combination of red-green-blue (RGB). white is RGB(255,255,255), black is RGB(0,0,0). Convert your image in a gray scale: take the color of every pixel (r,g,b) then compute c=(r+g+b)/3, so the gray pixel of a new image can be RGB(c,c,c), but you can simply store c somewhere. Then compute the mean value of c on all the image and compare it with a treshold. do something like this: if c_mean is less then 50 the image is too dark if c_mean is greater then 200 the image is too light hope helps :-D


      Russell

      N 1 Reply Last reply
      0
      • W Waldermort

        By taking a look at it I suppose... Please don't mark your topic with the word Urgent.

        Waldermort

        T Offline
        T Offline
        toxcct
        wrote on last edited by
        #4

        WalderMort wrote:

        Please don't mark your topic with the word Urgent.

        '5' for this :-D


        [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

        1 Reply Last reply
        0
        • S sujtha

          How to identify given image is too dark or light? Input format of the file is tif and jpg.

          K Offline
          K Offline
          KarstenK
          wrote on last edited by
          #5

          make a bitmap out of and test the pixels. -> CXImage article at CP

          Greetings from Germany

          1 Reply Last reply
          0
          • R Russell

            images are made of pixel, then every pixel has got a color, the color is a combination of red-green-blue (RGB). white is RGB(255,255,255), black is RGB(0,0,0). Convert your image in a gray scale: take the color of every pixel (r,g,b) then compute c=(r+g+b)/3, so the gray pixel of a new image can be RGB(c,c,c), but you can simply store c somewhere. Then compute the mean value of c on all the image and compare it with a treshold. do something like this: if c_mean is less then 50 the image is too dark if c_mean is greater then 200 the image is too light hope helps :-D


            Russell

            N Offline
            N Offline
            Nishad S
            wrote on last edited by
            #6

            Russell` wrote:

            compute c=(r+g+b)/3,

            But the brightness is not simply the average, right? Red has low intensity compared to others. I dont remember the exact ratio.

            - NS -

            R 1 Reply Last reply
            0
            • N Nishad S

              Russell` wrote:

              compute c=(r+g+b)/3,

              But the brightness is not simply the average, right? Red has low intensity compared to others. I dont remember the exact ratio.

              - NS -

              R Offline
              R Offline
              Russell
              wrote on last edited by
              #7

              I think you are right. If you find the right formula please post it here, I'll be happy to learn it. :-D In this case I think that him doesn't need an accurate extraction of the gray-scale, the simple formula (r+g+b)/3 can be enough.


              Russell

              N 1 Reply Last reply
              0
              • R Russell

                I think you are right. If you find the right formula please post it here, I'll be happy to learn it. :-D In this case I think that him doesn't need an accurate extraction of the gray-scale, the simple formula (r+g+b)/3 can be enough.


                Russell

                N Offline
                N Offline
                Nishad S
                wrote on last edited by
                #8

                Russell` wrote:

                If you find the right formula please post it here

                The one I know is Y = 0.3*R + 0.59*G + 0.11*B

                Russell` wrote:

                the simple formula (r+g+b)/3 can be enough

                If it is not for human recognition... right?

                - NS -

                R S 2 Replies Last reply
                0
                • N Nishad S

                  Russell` wrote:

                  If you find the right formula please post it here

                  The one I know is Y = 0.3*R + 0.59*G + 0.11*B

                  Russell` wrote:

                  the simple formula (r+g+b)/3 can be enough

                  If it is not for human recognition... right?

                  - NS -

                  R Offline
                  R Offline
                  Russell
                  wrote on last edited by
                  #9

                  NS17 wrote:

                  Y = 0.3*R + 0.59*G + 0.11*B

                  Yes! I was forgetting this!:doh: (r+g+b)/3 it only an approssimation of the right formula... I used this in past to implement a fast algorithm, but of course it isn't exact. :-D


                  Russell

                  1 Reply Last reply
                  0
                  • N Nishad S

                    Russell` wrote:

                    If you find the right formula please post it here

                    The one I know is Y = 0.3*R + 0.59*G + 0.11*B

                    Russell` wrote:

                    the simple formula (r+g+b)/3 can be enough

                    If it is not for human recognition... right?

                    - NS -

                    S Offline
                    S Offline
                    Sreedhar DV
                    wrote on last edited by
                    #10

                    What exactly are those constants 0.3 , 0.59 and 0.11 ?

                    Sreedhar DV [Real success is having courage to meet failure without being defeated.]

                    R 1 Reply Last reply
                    0
                    • S Sreedhar DV

                      What exactly are those constants 0.3 , 0.59 and 0.11 ?

                      Sreedhar DV [Real success is having courage to meet failure without being defeated.]

                      R Offline
                      R Offline
                      Russell
                      wrote on last edited by
                      #11

                      Our eye is more sensitive on the green light and less on red. So, that constants are related to the features of the human eye. hope it helps.


                      Russell

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups