Page 1 of 1

Find section of image with the most detail

Posted: 2016-12-02T13:58:11-07:00
by davich
Hi,
Say I have a 3000x3000 image. I want to programatically find which 600x600 square has the most detail in it. By detail, I mean lots of edges.

I basically want to show my users a close up section of an image to show them the quality of it, but without showing them the whole image in close up form. The small section of the image is only able to show quality if it has some fine detail in it (a 600x600 square of all the same color wouldn't work, but seeing lots of edges up close would).

Is there a way to get a numerical representation for how detailed an image is? I could do that over all of the sections and compare the values, maybe?

Thanks for your help. I don't know if I've explained this very well, so please ask me to clarify if anything doesn't make sense.

Re: Find section of image with the most detail

Posted: 2016-12-02T15:05:51-07:00
by fmw42
Do you want to shift the 600x600 window one pixel at a time or by 600 pixels?

If the former, then you can either use -statistic to get the standard deviation or you can convert the image to edges (-edge) and then do -statistic to get the mean(average). Then use

identify -define identify:locate=maximum -define identify:limit=2 statisticimage.png

to find the largest one. Then get the coordinates and draw a square on the image corresponding to those coordinates as the center of the square.

If the latter, then resize the image such that each resized pixel corresponds to 600x600 block in the original image. Do the same as above. But compute the corresponding point in the original image before drawing the square. For drawing see -draw.

See
http://www.imagemagick.org/script/comma ... ptions.php
http://www.imagemagick.org/script/comma ... #statistic
http://www.imagemagick.org/script/comma ... s.php#edge
http://www.imagemagick.org/Usage/draw/
http://www.imagemagick.org/script/comma ... php#resize
http://www.imagemagick.org/Usage/resize/
http://www.imagemagick.org/script/identify.php

Re: Find section of image with the most detail

Posted: 2016-12-02T17:14:09-07:00
by snibgo
As Fred says.

My "Details, details" page shows a number of measures for detail, where "detail" is measured within a small window (eg 10x10). Your required window is larger (600x600), so you can either increase the size of the detail window, or blur the result (for a sliding 600x600 window) or scale it (for 600x600 blocks).

Re: Find section of image with the most detail

Posted: 2016-12-02T18:40:46-07:00
by snibgo
davich wrote:By detail, I mean lots of edges.
I'll mention another issue concerning this.

We can get a value for each pixel that shows how much detail is there, and this gives us a value for every 600x600 square.

However, we might care about the entirety of each edge. For example, one candidate window might contain a single edge containing 300 pixels, while another window has two edges each containing only 100 pixels. Which window contain the "most detail"? Perhaps you want to count the edges themselves, rather than the count of pixels within edges.

Another example: if your display program automatically zooms in to the greatest detail, you might want to ensure that an edge structure isn't clipped by the border of the display window.

This problem, of integrating pixels into edge structures, isn't trivial. One complication is that binary edge detectors often create "broken" edges. (See my "Mending broken lines" page.)

Re: Find section of image with the most detail

Posted: 2016-12-11T17:09:36-07:00
by davich
Hi, thanks for your replies.

Fred, I'm having some trouble with the identify command. Here's what I'm getting:

$ identify -define identify:locate=maximum -define identify:limit=2 testimage3.png
testimage3.png PNG 1000x1000 1000x1000+0+0 8-bit PseudoClass 256c 64.3KB 0.000u 0:00.000
identify: IDAT: duplicate sRGB information ignored `testimage3.png' @ warning/png.c/MagickPNGWarningHandler/1754.
identify: IDAT: duplicate `testimage3.png' @ warning/png.c/MagickPNGWarningHandler/1754.
identify: IDAT: invalid chromaticities `testimage3.png' @ warning/png.c/MagickPNGWarningHandler/1754.

How do I get from this output to the coordinates of a square?

Thanks

Re: Find section of image with the most detail

Posted: 2016-12-11T18:00:52-07:00
by fmw42
What is your IM version and platform? What is testimage3.png and how did you create it?

Re: Find section of image with the most detail

Posted: 2016-12-12T16:04:07-07:00
by davich
I might be on an old version:
Version: ImageMagick 6.7.5-7 2014-09-30 Q8 http://www.imagemagick.org
on a Macbook Pro.

The image is a mean (average) image (of an edges image) created as per your instructions above. Here it is: http://imgur.com/Me4GkQq
$ convert testimage.png -edge 5 testimage2.png
$ convert testimage2.png -statistic Mean 20x20 testimage3.png

Thanks again for all your help!

Re: Find section of image with the most detail

Posted: 2016-12-12T17:07:19-07:00
by fmw42
That version is way too old to use identify to get your max location. That version is over 200 versions old. You should really upgrade.

You need at least

2013-08-29 6.8.6-10 Cristy <quetzlzacatenango@image...>
New identify define to output the location of the minimum, maximum, or mean pixel of the image (e.g. identify -define identify:locate=maximum -define identify:limit=7 rose).

But I have a slower prototype as a script that might work. See my script, maxima, at my link below.

Re: Find section of image with the most detail

Posted: 2017-03-20T23:01:12-07:00
by davich
Hi Fred! Sorry for the late follow up, but just wanted to say a huge THANK YOU! It's all working beautifully!

Thanks for your help :)