Page 1 of 1

Compare rgb values of a pixel

Posted: 2016-04-05T16:46:16-07:00
by baxterstockman
Hi,

this is a total beginner question, I know, but I'm banging my head against the wall and can't find a solution nowhere in the web.

I use wand with python and I grayscale my picture. Then after that I want to go over the picture check see if it's too light and if so make it darker. So I thought of just going over (after greyscaling) and checking if there is a pixel with the RGB value (145,145,145) and since this is too light I'll just stretch the contrast.

Therefore I have the following pseudo code:

Code: Select all

  with wand.image.Image (filename="myfile.png") as img:
         img.type='grayscalematte';
         img.save(filename="myfile.png")
         with Color('#919191') as too_light:
            for row in img:
                for col in row:
                    if (???):
                        img.contrast_stretch(black_point=0.0)
                        img.save(filename="myfile.png")
                        return 1
so with the two for loops I go over every column in the image, however, I don't know how to compare the RGB values. What I get from

Code: Select all

col
is

Code: Select all

srgb(0,0,0,0)
.

Anyone an idea how I could achieve this?

Re: Compare rgb values of a pixel

Posted: 2016-04-05T19:23:01-07:00
by fmw42
Why don't you just do the equivalent of getting the max pixel value. In command line, see

Code: Select all

convert image -format "%[max]" info:
returns values in your quantumrange of your Q8 or Q16 install. See http://www.imagemagick.org/script/escape.php

or

Code: Select all

convert image -format "%[fx:maxima]" info:
returns value between 0 and 1. See http://www.imagemagick.org/script/fx.php

Sorry I do not know the MagicWand equivalent.


Or look at the mean (average value).

Re: Compare rgb values of a pixel

Posted: 2016-08-20T04:38:46-07:00
by JeanneMorris
Frequently individuals will first change over the RGB qualities to the Lab colorspace and after that measure Euclidean separation in the 3-dimensional Lab colorspace. I have seen claims the Lab colorspace tries to model human elucidation of shading and not machine understanding of shading (like RGB), so the thought is that the separation between Lab vectors is more significant than the separation between RGB vectors. I don't have a reference for this other than the Wikipedia article so I'm not certain of the careful science behind it.