Compare rgb values of a pixel

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Posts: 1
Joined: 2016-04-05T16:06:11-07:00
Authentication code: 1151

Compare rgb values of a pixel

Post by baxterstockman »


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:
         with Color('#919191') as too_light:
            for row in img:
                for col in row:
                    if (???):
                        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


Code: Select all


Anyone an idea how I could achieve this?

User avatar
Posts: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Compare rgb values of a pixel

Post 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


Code: Select all

convert image -format "%[fx:maxima]" info:
returns value between 0 and 1. See

Sorry I do not know the MagicWand equivalent.

Or look at the mean (average value).

Posts: 1
Joined: 2016-08-20T04:30:21-07:00
Authentication code: 1151

Re: Compare rgb values of a pixel

Post 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.