Page 1 of 1
Find areas of interest in an image
Posted: 2018-10-28T11:01:11-07:00
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
where -interest is the maximum number of areas with the highest interest to be found, the output would be a crop geometry.
Re: Find areas of interest in an image
Posted: 2018-10-28T11:22:20-07:00
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.
Re: Find areas of interest in an image
Posted: 2018-10-28T12:35:45-07:00
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!
Re: Find areas of interest in an image
Posted: 2018-10-29T12:47:13-07:00
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?
Re: Find areas of interest in an image
Posted: 2018-10-29T13:16:44-07:00
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
Re: Find areas of interest in an image
Posted: 2018-10-29T13:56:39-07:00
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.
Re: Find areas of interest in an image
Posted: 2018-10-29T18:03:33-07:00
by fmw42
You need to specify a region size (geometry) after -statistic StandardDeviation, such as 3x3. See
https://imagemagick.org/script/command- ... #statistic