Find areas of interest in an image

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
Andi34
Posts: 7
Joined: 2018-10-28T06:46:35-07:00
Authentication code: 1152

Find areas of interest in an image

Post by Andi34 »

Is there a special command to get areas of interest (e. g. by finding clusters of high contrast) in ImageMagick?
I imagine a command like this

Code: Select all

convert -interest 3 image
where -interest is the maximum number of areas with the highest interest to be found, the output would be a crop geometry.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Find areas of interest in an image

Post by snibgo »

We can readily find the contrast, eg with "-statistic StandardDeviation". I show some other methods at Details, details. This can give us an image that is black-gray-white: light where the contrast is high, and dark where the contrast is low.

Finding clusters is less simple, and less well defined. For example, a group of 100 light pixels distant from another similar group is two clusters, but they might virtually merge, and we might want to call that one cluster.

Methods shown on K-clustering may be useful, to partition the black-gray-white image. Or we could threshold the black-gray-white image and use connected-components.
snibgo's IM pages: im.snibgo.com
Andi34
Posts: 7
Joined: 2018-10-28T06:46:35-07:00
Authentication code: 1152

Re: Find areas of interest in an image

Post by Andi34 »

Yes, this is what I tested some hours ago:

Code: Select all

convert ... -colorspace Gray -auto-gamma -sharpen 2x1 -statistic StandardDeviation
Your post is very helpful to find a performant solution, thank you for sharing!
kraftydevil
Posts: 10
Joined: 2017-05-01T22:24:31-07:00
Authentication code: 1151

Re: Find areas of interest in an image

Post by kraftydevil »

Andi34 wrote: 2018-10-28T12:35:45-07:00

Code: Select all

convert ... -colorspace Gray -auto-gamma -sharpen 2x1 -statistic StandardDeviation
I've tried this but I'm getting:

Code: Select all

convert: option requires an argument `-statistic' @ error/convert.c/ConvertImageCommand/2880.
Why would StandardDeviation not be found as an option?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Find areas of interest in an image

Post by snibgo »

What is your complete command?

You have three dots where IM expects an input image.

You have no output image.

You have a type but no geometry for "-statistic". See http://www.imagemagick.org/script/comma ... #statistic
snibgo's IM pages: im.snibgo.com
Andi34
Posts: 7
Joined: 2018-10-28T06:46:35-07:00
Authentication code: 1152

Re: Find areas of interest in an image

Post by Andi34 »

To complete my command - example:

Code: Select all

convert inputimg -colorspace Gray -auto-gamma -sharpen 2x1 -statistic StandardDeviation 3x3 outputimg
It's useful to append -contrast-stretch 0x0 or -normalize after -statistic ..., else the highest luminance will be very low for smaller geometries.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Find areas of interest in an image

Post by fmw42 »

You need to specify a region size (geometry) after -statistic StandardDeviation, such as 3x3. See https://imagemagick.org/script/command- ... #statistic
Post Reply