Find darkest region in the image

MagickWand for PHP is an object-oriented PHP interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning MagickWand for PHP.
Post Reply
jpsmaster16
Posts: 1
Joined: 2013-12-08T08:45:31-07:00
Authentication code: 6789

Find darkest region in the image

Post by jpsmaster16 » 2013-12-09T06:36:32-07:00

I own 249x99 pixels in an image.
I need to find the darkest region in the image. This region will have a maximum size of 60x30 pixels

I'm starting now with ImageMagick. Have an average experience in PHP.

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

Re: Find darkest region in the image

Post by fmw42 » 2013-12-09T11:55:05-07:00

Perhaps you should post a link to your image (post to dropbox and put link here). Also explain further -- need the pixels be contiguous or can they be scattered about the image?

The simplest way for any distribution is to just -threshold 0 and see how many black pixels you have. If too few, increment the threshold until you get sufficient numbers of black pixels.

If you need a contiguous rectangle, then create a black image of size 60x30 (or whatever is you smallest rectangle that is acceptable). Then use

compare -metric rmse -subimage-search -dissimilarity-threshold 1 yourimage blackimage resultimages

The position resulting will be the rectangle with the value closest to black.

Post Reply