How to determine the brightness of an area in a picture

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Wolfgang

How to determine the brightness of an area in a picture

Post by Wolfgang »

Hello,

I am new to this board. I searched for an answer but I didn't find any.

I use convert to put some text into pictures. Is there any way to determine the brightness and/or the colour within the targeted area of the picture, so that the colour of the text can be set appropriately?

Thanks in advance.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: How to determine the brightness of an area in a picture

Post by Bonzo »

One method would be to crop the area of an image you want the details for, resize it smaller, and use -identify.

How you get the information from -identify would depend on what you were using e.g. command line, php Perl etc.
Wolfgang

Re: How to determine the brightness of an area in a picture

Post by Wolfgang »

Bonzo wrote:One method would be to crop the area of an image you want the details for, resize it smaller, and use -identify.
That sounds promissing.
How you get the information from -identify would depend on what you were using e.g. command line, php Perl etc.
I want to do this in a shell script (thus: command line) on Linux.

Can you tell me where I can find more information about this? Are there any examples available?
Slig

Re: How to determine the brightness of an area in a picture

Post by Slig »

Wolfgang wrote: I want to do this in a shell script (thus: command line) on Linux.

Can you tell me where I can find more information about this? Are there any examples available?
You can take a look at this lots of shell scripts. I'm almost sure you'll find how to get the return of identify: http://www.fmwconcepts.com/imagemagick/index.php
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to determine the brightness of an area in a picture

Post by fmw42 »

User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to determine the brightness of an area in a picture

Post by anthony »

For brightness convert it to gray scale, and for outputing colors the txt: output is simplier

Code: Select all

  convert image -crop WxH+X+Y -resize 1x1\! -colorspace gray txt:
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply