-blur_selective

Selective blur preserves edges while reducing noise. Both phenomena exhibit very high rates of change, but noise tends to random, mutually cancelling impulses while edges exhibit a degree of coherency. This command tends to agressively blur noise in locales where the average rate of change is relatively low, impulses notwithstanding, while avoiding the softening of edges.

The command has the following format:

-blur_selective: sigma>=0,_edges>0,_nb_scales>0

Selective Gaussian Scaling

-blur_selective has two goals: preserve edges and smooth noise out of regions which, on average, do not change much, such as the blue background of the happy face or the yellow areas of the face. The second goal favors blurring, but this is not conducive to the first: preserving edges.

To resolve this, -blur_selective employs -gradient_norm as an edge detector. -gradient_norm produces a gray scale image where regions of rapid luminance or chromatic change in the subject image translate to light regions in the gradient norm, which are otherwise dark. It is sensitive to noise, but even more sensitive to the abutting of dissimilar regions in the original, producing a stronger signal — an edge — than noise pixels in isolation. 

The command generates extraction masks from a -quantized version of the gradient norm, one for each scale specified by nb_scales. The masks stemming from the lighter portions of the gradient norm isolate edges in the original, those stemming from darker regions isolate constant color and luminance regions. Masks on each end of this 'detail' spectrum can work in tandem to serve both goals. The less 'edgy' masks isolate regions in which noise may be aggressively smoothed. Those on the other end can isolate and copy off edges before any sort of blurring of the original takes place.

In operation, blur_selective derives extraction masks as needed from the quantized version of the gradient norm, starting with those on the edgy end of the detail spectrum. At each iteration, the command first uses the extraction mask to copy a region and then blurs the subject image a fraction — in particular, the fraction of sigma over the number of scales, less one. The quantized version of the gradient norm also serves as a save buffer, since the region reflecting a particular degree of edginess coincides with the shape of the mask and the region copied from the subject image; at each iteration, a portion of the output replaces the used part of the quantized gradient norm.

The first iteration copies off edges from an unblurred  subject image. Then, as the iteration proceeds, the extraction masks select from progressively blurred versions of the subject image, reducing noise somewhat in an inverse relation to the 'edginess' associated with the extraction mask. The last iterations mainly extract regions of largely constant luminance and chrominance.

When the iteration completes, the output image completely replaces the gradient norm and is a mosaic of the original subject image at different degrees of blurring, with edges preserved, but with noise reduced in more constant regions.

An optimal combination of parameters is image dependent and requires some experimentaton. If possible, one should find a relatively constant region, such as the sky in an outdoor photograph, and choose a sigma that just blurs out the noise. Too high a value of sigma tends to create halos around edges. The choice of _edges should be just high enough to preserve edges without an undue amount of noise also being preserved. _nb_scales should be just enough to render indistinguishable edges between regions with differing levels blurring.

Garry Osgood