Evaluate Blurriness/Sharpness Factor

Discuss digital image processing techniques and algorithms. We encourage its application to ImageMagick but you can discuss any software solutions here.
7eicher
Posts: 18
Joined: 2014-11-06T05:17:33-07:00
Authentication code: 6789

Re: Evaluate Blurriness/Sharpness Factor

Post by 7eicher » 2014-11-09T14:37:52-07:00

Hmm, Dropbox says I dont belonge there. Maybe you need to share these images?

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

Re: Evaluate Blurriness/Sharpness Factor

Post by snibgo » 2014-11-09T15:05:43-07:00

snibgo's IM pages: im.snibgo.com

7eicher
Posts: 18
Joined: 2014-11-06T05:17:33-07:00
Authentication code: 6789

Re: Evaluate Blurriness/Sharpness Factor

Post by 7eicher » 2014-11-10T01:06:39-07:00

Now it works.

7eicher
Posts: 18
Joined: 2014-11-06T05:17:33-07:00
Authentication code: 6789

Re: Evaluate Blurriness/Sharpness Factor

Post by 7eicher » 2014-11-10T02:37:59-07:00

I have written a small script in node to perform some tests over files based on the deviation method, you have provided earlier. Here test results for 3 images:

DegStep: 15 maxDeg: 180 cropPerc: 100

blurry.jpg 0x1: [ '0.47640', '0.09185' ]
blurry.jpg 0x3: [ '0.41651', '0.29287' ]
blurry.jpg 0x6: [ '0.31874', '0.52985' ]
blurry.jpg 0x10: [ '0.25817', '0.75947' ]
blurry.jpg 0x20: [ '0.23722', '1.43315' ]
sharp.jpg 0x1: [ '0.57534', '0.13403' ]
sharp.jpg 0x3: [ '0.54890', '0.44267' ]
sharp.jpg 0x6: [ '0.54524', '0.95326' ]
sharp.jpg 0x10: [ '0.53005', '1.51992' ]
sharp.jpg 0x20: [ '0.53336', '2.91220' ]
CRB_7983.TIF 0x1: [ '0.30716', '2.67845' ]
CRB_7983.TIF 0x3: [ '0.40087', '6.94035' ]
CRB_7983.TIF 0x6: [ '0.41218', '10.79834' ]
CRB_7983.TIF 0x10: [ '0.40965', '14.28854' ]
CRB_7983.TIF 0x20: [ '0.39220', '19.64742' ]

I will explain the numbers:

0x1, 0x3, ... are the blurriness applied on the same images. I was interested in how the deviation changes in relation to different blurriness strength. It might indicate how strong is a blur in an image, can it be tolerated or not.

DegStep: 15 (Steps of degree, each 15deg a test)
maxDeg: 180 (Max. degree, 180deg, half the the rotation is enough to get every direction)
cropPerc: 100 (well, the image could be cropped at center gravity, in this case its 100%, so not croppped)

The deviation numbers:

[ '0.47640', '0.09185' ]

1. number: Ratio between: Diff min to max and Diff max to total (maxDegDevi - minDegDevi) / (originalDeviation - minDegDevi)
2. number: Diff min to max, percentage to total (maxDegDevi - minDegDevi) / originalDeviation * 100

When looking at our initial image: CRB_7983.TIF 0x3: [ '0.40087', '6.94035' ]

We can see a high rate of difference between the minimum and maximum deviations found in the different tested directions. 6.9% of the overall deviation is big and indicates clearly a blurriness based on linear motion.

When testing this against two images, which are pretty similar, one sharp and the other with moderate motion blur, we can see the difference of min. and max. deviation is not representative. Actually its saying the opposite:

blurry.jpg 0x3: [ '0.41651', '0.29287' ]
sharp.jpg 0x3: [ '0.54890', '0.44267' ]

0.29287 (blurry) against 0.44267 (sharp). That should be actually the opposite. So the algorithm might only work with strong blurrines. See here the two new images (sharp.jpg, blurry.jpg): https://www.dropbox.com/sh/tnjkomqf7556 ... 89ITa?dl=0

I will check your new approach.

7eicher
Posts: 18
Joined: 2014-11-06T05:17:33-07:00
Authentication code: 6789

Re: Evaluate Blurriness/Sharpness Factor

Post by 7eicher » 2014-11-10T02:49:19-07:00

Sorry, are the numbers clear for you?

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

Re: Evaluate Blurriness/Sharpness Factor

Post by snibgo » 2014-11-10T11:00:45-07:00

"-motion-blur" is not symmetrical. Therefore 30 degrees will be different to 210 degrees. However, the difference will be small.

You say the two numbers eg [ '0.47640', '0.09185' ] are calculated as:

1. (maxDegDevi - minDegDevi) / (originalDeviation - minDegDevi)
2. (maxDegDevi - minDegDevi) / originalDeviation * 100

where maxDegDevi is the maximum standard deviation found at a rotation, etc.

But when one number goes up, the other goes down. I think this is unlikely. Perhaps there is a mistake in the script.

I don't see what number 1. measures. It is very sensitive to the difference between the the original SD and the minimum SD. I don't think this is a useful result.

Your subtract the standard deviations, (max - min). I think a better measure is to divide, (max / min).

Here are the numbers for blurry.jpg. At 45 degree intervals, maximum is at 225 degrees, minimum is at 315 degrees. I calculate (max-original)/(min-original).

0x1 1.70044
0x2 1.662
0x3 1.57649
0x4 1.50755
0x5 1.4522
0x6 1.40653

The same for sharp.jpg. Max is at 90 degrees, min is at 0 degrees.
0x1 1.91244
0x2 2.04636
0x3 2.099
0x4 2.12051
0x5 2.12657
0x6 2.13073

Oh dear. This says that sharp.jpg is more blurry than blurry.jpg. This is wrong. Perhaps the theory is wrong, or too simplistic.
snibgo's IM pages: im.snibgo.com

7eicher
Posts: 18
Joined: 2014-11-06T05:17:33-07:00
Authentication code: 6789

Re: Evaluate Blurriness/Sharpness Factor

Post by 7eicher » 2014-11-10T12:23:34-07:00

After all, I go sleeping now... :)

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

Re: Evaluate Blurriness/Sharpness Factor

Post by snibgo » 2014-11-10T20:26:46-07:00

The problem with sharp.jpg is the strong horizontal lines in the stairs. When smeared sideways, the SD doesn't drop much. When smeared vertically, the SD drops a lot.

So my test correctly picks up the horizontal lines, but can't tell if they are due to camera shake or the subject matter.
snibgo's IM pages: im.snibgo.com

7eicher
Posts: 18
Joined: 2014-11-06T05:17:33-07:00
Authentication code: 6789

Re: Evaluate Blurriness/Sharpness Factor

Post by 7eicher » 2014-11-11T13:16:42-07:00

I think to check the high frequencies might be a more robust approach... not yet into it. but thats probably the way

JoaCHIP
Posts: 37
Joined: 2004-12-21T04:22:18-07:00
Location: Copenhagen

Re: Evaluate Blurriness/Sharpness Factor

Post by JoaCHIP » 2014-11-27T02:46:33-07:00

Oh, why did I miss this interesting discussion. I've done stuff like this using ImageMagick, and I think you might want to look into the FFT stuff. Now I'm at work atm. so I can't dive into this topic, but I believe you would be able to deduct a lot of information about blurryness from the FFT data.

A quick word of advice regarding the FFT transformed output: The "large" details will show up at the center of the FFT image. Towards the corners you'll find the smaller and smaller frequencies. Expect higher values (brigther pixels) towards the center. This is normal. Also, the scale of dimensions is logaritmic, so the center 10 x 10 pixels carry information for a much more important part of the image than 10 x 10 pixels anywhere else on the FFT image.

Basically an FFT transformation is "calibrated" in a way that'll make straight 'white noise' appear "equal", which is not very typical for a photo. Also, I believe that the distribution of energy in an average photo will be somewhat similar to 'pink noise', which is why the center of the FFT view will typically show a bright start (increased energy levels at the lower frequencies).

Maybe the easiest approach is to do an FFT of two images: A sharp and a blurred one, and then compare them to learn how to best recognize the difference.

My own gallery uses ImageMagick's FFT to do something very similar: Recognizing "directions" in the image. Notice how the "M" in graffiti here has a lot of tilted lines at a certain angle:

Image

This angle then shows up in my FFT based analysis, causing a "spike" in my data at that same angle:

Image

7eicher
Posts: 18
Joined: 2014-11-06T05:17:33-07:00
Authentication code: 6789

Re: Evaluate Blurriness/Sharpness Factor

Post by 7eicher » 2014-11-30T06:25:50-07:00

Thanks Joa for your reply, its not too late :)

FFT looks very promising, could you provide a simple IM command line, to see how such a high frequency image could be created?

User avatar
fmw42
Posts: 25757
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Evaluate Blurriness/Sharpness Factor

Post by fmw42 » 2014-11-30T12:39:18-07:00

See http://www.fmwconcepts.com/imagemagick/ ... urier.html

convert lena.png -fft lena_mp_fft.png
convert lena_mp_fft-0.png -contrast-stretch 0 -evaluate log 10000 lena_spectrum.png

7eicher
Posts: 18
Joined: 2014-11-06T05:17:33-07:00
Authentication code: 6789

Re: Evaluate Blurriness/Sharpness Factor

Post by 7eicher » 2014-12-03T06:21:20-07:00

Thanks for link.

I tested against two similar images, one with slight motion blur and one acceptably sharp. By eye we can see that the magnitudes differ, that we can recognise a clear direction for the blurry image (2nd).

For my project, I have thousands of images and dont want to look at every image. Do you have an idea how to calculate a certain degree of direction in the magnitude image. The best would be to have certain index/magnitude of direction and by a manually defined threshold we could distingiush between more sharpy and less sharpy images. Any ideas?

1) Sharp

Image
Image

2) Blurry

Image
Image

User avatar
fmw42
Posts: 25757
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Evaluate Blurriness/Sharpness Factor

Post by fmw42 » 2014-12-03T11:40:55-07:00

Strong lines in the spectrum will be perpendicular to strong edges in the images. I am not sure how this relates to blurriness other than to reduce the strength of the edges in the spectrum.

7eicher
Posts: 18
Joined: 2014-11-06T05:17:33-07:00
Authentication code: 6789

Re: Evaluate Blurriness/Sharpness Factor

Post by 7eicher » 2014-12-03T15:24:49-07:00

its not the strong lines, rather the dense point cloud. The cloud of the sharp image is present overall equally around the center. For the blurry image the cloud extremety bounds towards top-left and bottom-right.

Post Reply