• Stars
    star
    141
  • Rank 259,971 (Top 6 %)
  • Language
    C
  • License
    ISC License
  • Created about 11 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Some implementations of algorithms for blur detection in JPEGs

This comes from some work I did on a contract a few years ago. While I obviously canโ€™t publish everything related to that work, I had retained the copyright to some of the low-level implementations exactly so that I could open source them later.

(N.B.: This code is now explictly licensed, per the LICENSE file.)

What follows are some notes I had written about a broader approach that was built on this code. I expect that research in this area has since surpassed this approach.

Overview

This is an attempt to synthesize an algorithm for automatic ranking of digital photographs, based on the following basic assumptions about quality:

  • good photos have the subject matter in focus;
  • the focal mass will generally lie close to the points defined by the rule of thirds;
  • the subject matter will also be separated from the background by brightness and saturation.

We note that the sharpness of a region is a reasonable predictor of focus, as most prominent subject matter contains detailed edge structures that are destroyed by out-of-focus/motion blur.

After the description of the algorithm and the work on which it is based, I discuss directions for improvement.

Review of Prior Work

Our approach broadly builds upon the approach suggested by Lim, Yen, and Wulim-yen-wu, though their goal is simply making a decision as to whether an image is out-of-focus or not.

A related set of ideas for determining the aesthetic value of an image is given by Liu et al.liu-et-al, but their focus is on reframing an existing image to capture the most aesthetic possible cropping of an image.

Description of the Algorithm

Given an image, we first decompose it into square blocks of pixels. We have chosen 64x64 pixels rather than the arbitrary 100x100 suggested in lim-yen-wu to facilitate the incorporation of Discrete Cosine Transform (DCT) information in the common case that the image is JPEG encoded.

Blockwise Metrics

For each block, we compute the hue, saturation, and intensity of each pixel. Note that it might be possible to speed up the algorithm here by skipping this computation and using only luminance values for blurred blocks.

We wish to make a boolean decision about whether this block is likely to be in focus, based on whether the sharpness of this block exceeds a threshold. In the present implementation, we have three different sharpness metrics. We will describe each, as well as a proposed unification of the methods.

Sharpness via DCT coefficients

In the case that we have access to DCT information, we can perform a simple histogram algorithm due to Marichal, Ma, and Zhang (marichal-ma-zhang). For each 8x8 DCT block in this image block, we count the occurance of coefficients greater than a minimum value in a histogram. After each DCT block has been considered, we compare each value in the histogram against the histogram value for the first coefficient (0,0), summing a weighted value when the value exceeds a threshold.

This provides an extremely rapid approximation of blur extent. In the case that this value exceeds certain thresholds, it would be possible to skip further computation of more accurate sharpness metrics.

Sharpness via a Wavelet-based Edge Detector

Tong et al.tong-li-zhang-zhang present an approach to blur estimation based on the Haar wavelet transform, whereby specific edge structures can be detected, and the ratio of Dirac and abrupt-step structures to roof and gradual step edge structures provides an acceptable estimation of the sharpness of the given block.

In our case, we have modified this algorithm to skip the windowing step, as we felt that adjusting the thresholds by which a point was classified was more effective than performing non-maximum suppression (NMS).

Unfortunately, even without NMS, this is the most computationally expensive of the algorithms implemented.

In his masterโ€™s thesis ramakrishnan-thesis, Harish Ramakrishnan presents some variants on this approach and evaluates their performance.

Sharpness via an IIR Filter

Shaked and Tastlshaked-tastl derive a model of sharpness based on the ratio between high-frequency data and low-frequency data, and present an approach to computing this metric via a pair of one-dimensional IIR filters. The advantage of this decomposable approach is that rows or columns can be skipped to speed up the process at the cost of accuracy.

Presently we use simple Butterworth high- and low-pass filters on row and column data to compute the sharpness metric. However, it seems likely that better filter designs could help improve the accuracy and performance of this model.

Alternative Sharpness Measures

A Canny edge detector could be used in much the same way as the Haar transform approach given above. It is possible that this could be more efficient.

Another alternative, discussed in ramakrishnan-thesis, is the perceptual blur metric given by Marziliano et al. in marziliano-et-al. We have thus far not considered using this blur metric as it seems less efficient than the methods we already implement.

Combining Sharpness Metrics

In general, we avoid using the IIR filter in preference to the wavelet transform approach or the DCT coefficient histogram. Ideally, we would use the fastest and least-accurate methods (DCT coefficients, IIR filter with a large row/column skip) to eliminate clearly blurry blocks, and then only use the more expensive wavelet transform approach on blocks whose sharpness isnโ€™t evident.

Other block-level metrics

Along with a sharpness value for each block, we also compute the means of the blockโ€™s hue, intensity, and saturation values, as well as a ratio of the number of pixels having a hue similar to that of blue sky (per lim-yen-wu).

Global merits

Having computed these metrics for each block in the image, we compute several global indicators of quality. Blocks whose dominant hue is that of blue sky are ignored during this process.

We compute a composition score as a sum of the blocks which are sharp, weighted by the Manhattan distance of the block from one of the four โ€œpower pointsโ€ representing intersections of the division of the image in thirds, as per the rule of thirds.

We compute brightness and saturation indices as the difference between the mean of those values for blocks considered sharp and the mean of those values for the remaining blocks.

We also compute the density of sharp blocks, as the ratio of sharp blocks to unsharp ones, and the median block sharpness.

Weighted ranking

This is where work needs to proceed: improving the quality of indices other than composition so they can be combined with appropriate weights to produce a single ranking value.

Presently we can provide a ranking based on Lim et al.โ€™s process for deciding if an image is in focus: compute the sum of composition, brightness, and saturation weighted by density and median sharpness, as well as individual weights prioritizing composition over brightness and saturation.

Directions for Further Work

The composition weighting could be improved in a number of ways. Perhaps the Manhattan distance from a power point is insufficient, and a more sophisticated model of the rule of thirds is required. Another possible direction is incorporating the idea of balanced masses as discussed in liu-et-al; note that within our presented approach, we could simplify that scheme by considering each block a unit of mass based on its sharpness value.

Lim et al.โ€™s sky hue ratio is questionable and it remains to be seen if it is indeed an effective metric for our purposes.

References

lim-yen-wu Suk Hwan Lim, Jonathan Yen, Peng Wu, *Detection of Out-Of-Focus Digital Photographs*, HPL-2005-14, 2005.

tong-li-zhang-zhang Hanghang Tong, Mingjing Li, Hongjiang Zhang, Changshui Zhang, *Blur detection for digital images using wavelet transform*, Proceedings of the IEEE International Conference on Multimedia & Expo, 2004.

marichal-ma-zhang Xavier Marichal, Wei-Ying Ma, Hongjiang Zhang, *Blur determination in the compressed domain using DCT information*, Proceedings of the IEEE ICIP, pp.386-390, 1999.

liu-et-al Ligang Liu, Renjie Chen, Lior Wolf, Daniel Cohen-Or, *Optimizing Photo Composition*, Computer Graphics Forum, 29: 469-478, 2010.

ramakrishnan-thesis Harish Ramakrishnan, *Detection and Estimation of Image Blur*, Masterโ€™s Thesis, 2010.

shaked-tastl Dored Shaked, Ingeborg Tastl, *Sharpness Measure: Towards Automatic Image Enhancement*, HPL-2004-84, 2004.

marziliano-et-al Marziliano, P.; Dufaux, F.; Winkler, S.; Ebrahimi, T; *A no-reference perceptual blur metric*, Proceedings of International Conference on Image Processing, 2002.

More Repositories

1

build-your-own-shell

Guidance for mollusks (WIP)
Tcl
379
star
2

series

unofficial mirror of git://git.code.sf.net/p/series/series (Richard C. Waters' SERIES package for Common Lisp)
Common Lisp
49
star
3

imago

image manipulation library for Common Lisp
Common Lisp
48
star
4

niffy

NIF testing harness
C
32
star
5

fixie-trie

Compact tries for fixed-width keys
Rust
26
star
6

extrospect-beam

Tools for live extrospection of the Erlang BEAM VM โ€” WARNING: early alpha
C
23
star
7

tsdl-image

OCaml SDL2_image bindings to go with Tsdl
OCaml
14
star
8

magic-ringbuffer-rs

Attempt at implementing the Magic Ringbuffer in Rust
Rust
11
star
9

tsdl-mixer

SDL2_mixer bindings to go with Tsdl
OCaml
8
star
10

granderl

Fast-and-loose PRNG NIF
C
8
star
11

tsdl-ttf

SDL2_ttf bindings for Ocaml with Tsdl
OCaml
7
star
12

goose-theme

A gray color theme
Emacs Lisp
7
star
13

wacom-serial-iv

Linux driver for old Wacom serial tablets, protocol IV
C
7
star
14

shred-for-satan

MIDI-driven metronome
OCaml
7
star
15

convergence

Personal archaeology: a GBA game in literate assembly
Assembly
6
star
16

m68k-assembler

A simple, mostly-DevPAC-compatible assembler for the Motorola 68k series of proccessors.
Common Lisp
6
star
17

punchy-the-log

Simple demonstration of hole punching for logging
C
4
star
18

tiny-compact-map

Simple compact popcount array map
Rust
4
star
19

dispatch-comparison

Do not use: rhetorical benchmark
Python
4
star
20

ymamoto

A replay routine for the Atari ST, using the YM2149 chip.
Assembly
4
star
21

advent-of-code-2017

Python
4
star
22

mechanizerl

Web testing tool for Erlang modelled after WWW::Mechanize
Erlang
3
star
23

zookicker

#1GAM February backup plan
OCaml
3
star
24

hyper-ballon-struggle

Restoration of weekend GBA game from 2002 for #1GAM
Assembly
3
star
25

st-linker

A very simple linker to use with m68k-assembler. Outputs Atari ST PRG files.
Common Lisp
3
star
26

erl-tcp-metrics

Read Linux kernel TCP metrics from Erlang
C
3
star
27

erl-dirwatch

Simple directory watching for Erlang
C
3
star
28

pink-bliss-theme

Alex Schroeder's Pink Bliss emacs theme updated for emacs24
Emacs Lisp
2
star
29

parsur

Parser combinators library for Ur/Web
Makefile
2
star
30

cl-ftgl

FTGL bindings for Common Lisp
Common Lisp
2
star
31

griffin

An emacs-driven static blog generator
Emacs Lisp
2
star
32

advent-of-code-2016

Suggested name: legendary-octo-carnival
Common Lisp
1
star
33

normalize-iplist

A gem that probably isn't useful to you
C
1
star
34

talk-swl2017-timing-wheels

Slides from Timing Wheels talk at Systems We Love in Minneapolis
TeX
1
star
35

dentata-alpha

Personal archaeology: an early game library (very obsolete)
C
1
star
36

noose

Trivial command-line newsreader
C
1
star
37

fobwart-alpha

Personal archaeology: a networked game (obsolete)
C
1
star
38

evil-zips

Lovingly crafted zip files for testing restricted unzip implementations
1
star
39

dentata-beta

Personal archaeology: an early game library (obsolete)
C
1
star
40

mumble

Mumble is a package for converting text representations of music into data for specific playroutines.
Common Lisp
1
star
41

6502core

Personal archaeology: 6502 assembler and emulator -- do not use
C
1
star
42

lalr-parser-generator

LALR parser generator; generates Common Lisp output.
Common Lisp
1
star
43

urweb

Unofficial mirror of the Ur/Web compiler
Standard ML
1
star
44

strap

Personal archaeology: tool for "unbooting" a machine (obsolete)
Assembly
1
star
45

green-threading-shootout

C
1
star
46

steaghan

Personal archaeology: a tool for steganography (obsolete)
C
1
star
47

til

Today I Learned
1
star