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.
Post Reply
baxterstockman
Posts: 1
Joined: 2016-04-05T16:06:11-07:00
Authentication code: 1151

Compare rgb values of a pixel

Post by baxterstockman » 2016-04-05T16:46:16-07:00

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?

User avatar
fmw42
Posts: 22081
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Compare rgb values of a pixel

Post by fmw42 » 2016-04-05T19:23:01-07:00

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

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

Re: Compare rgb values of a pixel

Post by JeanneMorris » 2016-08-20T04:38:46-07:00

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.

Post Reply