Find section of image with the most detail

Discuss digital image processing techniques and algorithms. We encourage its application to ImageMagick but you can discuss any software solutions here.
Post Reply
davich
Posts: 4
Joined: 2016-12-02T13:50:18-07:00
Authentication code: 1151

Find section of image with the most detail

Post by davich » 2016-12-02T13:58:11-07:00

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.

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

Re: Find section of image with the most detail

Post by fmw42 » 2016-12-02T15:05:51-07:00

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

snibgo
Posts: 9385
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Find section of image with the most detail

Post by snibgo » 2016-12-02T17:14:09-07:00

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).
snibgo's IM pages: im.snibgo.com

snibgo
Posts: 9385
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Find section of image with the most detail

Post by snibgo » 2016-12-02T18:40:46-07:00

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.)
snibgo's IM pages: im.snibgo.com

davich
Posts: 4
Joined: 2016-12-02T13:50:18-07:00
Authentication code: 1151

Re: Find section of image with the most detail

Post by davich » 2016-12-11T17:09:36-07:00

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

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

Re: Find section of image with the most detail

Post by fmw42 » 2016-12-11T18:00:52-07:00

What is your IM version and platform? What is testimage3.png and how did you create it?

davich
Posts: 4
Joined: 2016-12-02T13:50:18-07:00
Authentication code: 1151

Re: Find section of image with the most detail

Post by davich » 2016-12-12T16:04:07-07:00

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!

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

Re: Find section of image with the most detail

Post by fmw42 » 2016-12-12T17:07:19-07:00

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.

davich
Posts: 4
Joined: 2016-12-02T13:50:18-07:00
Authentication code: 1151

Re: Find section of image with the most detail

Post by davich » 2017-03-20T23:01:12-07:00

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 :)

Post Reply