Quantitative analysis of grayness

Forums Forums Get Technical Software Quantitative analysis of grayness

Viewing 15 posts - 1 through 15 (of 20 total)
  • Author
    Posts
  • #1924
    CauseISaidSo
    Participant

    The discussion in the “black, white & gray all over” thread lead me to wonder how one might quantitatively evaluate the “grayness” of a picture, which in turn lead me to write a quick ?n dirty app last night. I found the results pretty interesting, so I thought I?d share it here.

    The app is written in C# and requires .NET Framework 2.0 (which should allow it to run under Mono for the Mac/Linux people, but no guarantees). It?s a pretty simple app, so I have no problem sharing the source, too. If you?re interested in a copy, just PM me and let me know if you want the binary or binary & source. If there?s enough interest, I can just upload it to a public repository somewhere and post a link.

    The user interface is pretty simple:

    Enter the URL or file location in the Image URL box and click Load. This displays the picture in the area below. The “Max RGB Error” is the maximum deviation from pure gray that you?re interested in and defaults to 10% of the RGB range (10% of 256 = about 25). Use the Refresh button to refresh the display if the Max RGB Error is changed. The Display Method selects which error analysis to display (there are 9). I?ll cover each display method in a separate post so keep from having one monster post.

    First, some definitions:

    Most probably already know this, but color images are coded using values with a range of 0 to 255 with a separate value for each of the red, green, and blue components. So, RGB(255,255,255) is the max of all 3 components and equals white, while RGB(0,0,0) is black and RGB(255,0,0) is pure red.

    As used here, the Average Gray Value (AGV) of a pixel is the average of the R, G, and B components (R+G+B / 3). A pixel with an RGB of (128, 72, 106) would have an AGV of 102.

    Component Error (CE) is the absolute value of the difference between the actual value of an RGB component and its pixel?s AGV. So, for the pixel with RGB(128, 72, 106) and an AGV of 102, the CE for red is 128-102 = 26, the CE(G) = 30, and the CE(B) = 4.

    I?ve picked a couple of pictures from the thread just to illustrate the display modes (not picking on anybody or implying anything about these pics). Click on any picture to open a full-size version.

    Display Method: Normal

    Displays the picture normally:

    #31142
    CauseISaidSo
    Participant

    Display Method: Errors in red

    Highlight in red all pixels with any component error that exceeds the Max RGB Error. Error Count is the number of red pixels and the percentage of red pixels versus total pixel count:

    #31143
    CauseISaidSo
    Participant

    Display Method: Error mask

    Same as Errors in red, except all error pixels are white and everything else is black:

    #31144
    CauseISaidSo
    Participant

    Display Method: Average error distance

    Illustrates the distance that the average component error is from the max error. For our sample pixel RGB(128, 72, 106), the average CE is 20. With a max error of 25, that scales to 20/25 * 255 = 204, so the pixel would get colored RGB(204,204,204):

    #31145
    CauseISaidSo
    Participant

    Display Method: Largest error distance

    Same as previous, but uses whichever component error is largest. For our sample pixel, the largest CE is 30, which scales to the max value of 255, so the pixel would be colored white (255,255,255):

    #31146
    CauseISaidSo
    Participant

    Display Method: Largest error distance (color coded)

    Same as Largest error distance, but colors the pixels with the component that has the largest error instead of gray. For our sample pixel, green has the largest CE at 30 which scales to the max value of 255, so our pixel would be colored pure green (0,255,0):

    #31147
    CauseISaidSo
    Participant

    Display Method: RGB error distance

    Changes the color component of each pixel to show its relative distance from the max error value. For our sample pixel, CE(R)=26 which scales to 255, CE(G)=30 which scales to 255, and CE(B)=4 which scales to 4/25 * 255 = 41 so the pixel would be colored (255,255,41):

    #31148
    CauseISaidSo
    Participant

    Display Method: Subtract gray

    Subtracts the lowest color component value from all color components. For our sample pixel, the lowest value is green at 72, so subtracting 72 from the other components gives us (30,0,34):

    If there?s anything visibly recognizable with this one, it might have too much color for a B&W/gray theme. For a pure B&W image (or a color one that?s been completely desaturated), this would produce a completely black image.

    #31149
    CauseISaidSo
    Participant

    Display Method: Absolute RGB error distance

    Starts with the Subtract gray method, then scales the leftover color components as a percentage of the maximum error. This shows exactly which colors are pushing a pixel out of pure grayness. For our sample pixel, after subtracting gray we wound up with (30,0,34). Scaling that to a max error of 25 gives us (255,0,255), which is pure magenta and shows us that there?s much more red & blue in this pixel than green:

    That?s it. Like I said, if anyone?s interested the app to play around with just let me know.

    #31150
    Elsinore
    Keymaster

    Interesting. I’ve just kind of done it by brute force, using the color dropper tool and sampling a large number of pixels across the image. A color image may have some subset of pixels that is a perfect mix of RGB (e.g. 72, 72, 72; 119, 119, 119; or 23, 23, 23; ), but for the most part there will be at least a little random deviation (e.g. 72, 70, 67; 103, 105, 102; or 26, 20, 24) in a photo that appears monochromatic but is in fact a color photo. Photos that have been desaturated or shot in b/w will have all their pixels a perfect mix of RGB with no deviations.

    #31151
    CauseISaidSo
    Participant

    Exactly. So if you set the Max RGB Error to 1, run an image through the Errors in red or Error mask filters, and it returns an error count of 0, then every pixel in that image is a shade of pure gray.

    #31152
    Kestrana
    Participant

    Wow that’s really cool

    #31153
    U-Man
    Participant

    I love the geekiness of this community. 🙂

    Really, I do.

    #31154
    ravnostic
    Participant

    Yeah, I used to think I was a geek, but then I found you people. Now I’m just a nerd.

    I’d be glad to host the program on my hosting site (just a right-click-save-as file, really). Plenty of room to spare.

    #31141
    CauseISaidSo
    Participant

    Thanks for the kind words, all.

    And thanks for the offer, ravnostic. I haven’t gotten any requests for it yet (probably afraid of binaries from unknown sources and can’t say as I blame anyone), but if I do I might take you up on that.

    It really has a pretty limited usefulness, other than just playing around and seeing what different images look like through the filters (which I ended up doing for a few hours after I wrote it :)).

Viewing 15 posts - 1 through 15 (of 20 total)
  • You must be logged in to reply to this topic.