Krita Gaussian Noise Reduction

  

Gaussian noise reduction in digital images using a modified fuzzy filter Abstract: Noise can be easily induced in images during acquisition and transmission. Therefore, it is a basic requirement to remove noise from an image while keeping its features intact for better understanding and recognition.

  1. Making your Noise Reduction Layer Now that I have removed the larger problematic pieces using the easiest ways to remove grain in Photoshop, I can duplicate my layer. This is done as it was previously, using Control + J or Command + J.
  2. The reduction of noise in an image, considered as a goal itself or as a pre-processing step, is an important issue. Besides classical filters, a wide variety of fuzzy filters has been developed.
  3. Noise modeled as a standard complex Gaussian distribution p(z) = 1 ˇ exp(j zj2) (1) where z = Aei is a vector with amplitude A and phase, and given a set of noise reduction lters F = ff 1;f 2;:::;f kg, nd f p 2F such that MSE(f p(X)) MSE(f q(X)) 8f q 2F (2) where MSE(f q(X)) = 1 nm Xn i=0 Xm j=0 (f q(X ij) T ij)2 (3) and where T is the ideal.
  4. Experimental results with six of the most common images and various levels of white Gaussian noise demonstrate that the proposed model has achieved good and stable denoising performance in terms of subjective visual quality, PSNR and SSIM, as well as 0.68 dB - 8.67 dB (PSNR) and 0.07 - 0.48 (SSIM) gains higher than those in the other reference.

Auto Brush¶

The generic circle or square. These brush tips are generated by Krita through certain parameters.

Types¶

First, there are three mask-types, with each the circle and square shape:

Default

This is the ultimate generic type. The Fade parameter produces the below results. Of the three auto brushes, this is the fastest.

Soft

Krita Gaussian Noise Reduction Software

This one’s fade is controlled by a curve!

Gaussian

This one uses the gaussian algorithm to determine the fade. Out of the three auto brushes, this is the slowest.

Parameters¶

Diameter

The pixel size of the brush.

Ratio

Whether the brush is elongated or not.

Fade

this sets the softness of the brush. You can click the chain-symbol to lock and unlock these settings. Fade has a different effect per mask-type, so don’t be alarmed if it looks strange, perhaps you have the wrong mask-type.

With fade locked.

With fade separately horizontal and vertical.

Angle

This changes the angle a which the brush is at.

Spikes

This gives the amount of tips related to the ratio.

Density

This determines how much area the brush-covers over its size: It makes it noisy. In the example below, the brush is set with density 0%, 50% and 100% respectively.

Randomness

This changes the randomness of the density. In the example below, the brush is set with randomness 0%, 50% and 100% respectively.

Spacing

Krita Gaussian Noise Reduction System

This affects how far brushes are spaced apart. In the below picture, the three examples on the left are with spacing 0, 1 and 5.

Auto (spacing)

Ticking this will set the brush-spacing to a different (quadratic) algorithm. The result is fine control over the spacing. In the below picture, the three examples on right are with auto spacing, 0, 1 and 5 respectively.

Smooth lines

This toggles the super-smooth anti-aliasing. In the below example, both strokes are drawn with a default brush with fade set to 0. On the left without smooth lines, and the right with. Very useful for inking brushes. This option is best used in combination with Auto Spacing.

Precision

This changes how smooth the brush is rendered. The lower, the faster the brush, but the worse the rendering looks.You’d want an inking brush to have a precision of 5 at all times, but a big filling brush for painting doesn’t require such precision, and can be easily sped up by setting precision to 1.

Auto (precision)

This allows you to set the precision linked to the size. The first value is the brush size at which precision is at last 5, and the second is the size-difference at which the precision will decrease.

For example: A brush with ‘’starting brush size’’ 10 and ‘’delta’’ 4, will have…

  • precision 5 at size 10

  • precision 4 at size 14

  • precision 3 at size 18

  • precision 2 at size 22

  • precision 1 at sizes above 26.

Predefined Brushes¶

If you have used other applications like GIMP or Photoshop, you will have used this kind of brush. Krita is (mostly) compatible with the brush tip definitions files of these applications:

abr

Gimp autobrush tip definitions.

*.gbr

Gimp single bitmap brush tip. Can be black and white or colored.

*.gih

Gimp Image Hose brush tip: contains a series of brush tips that are painted randomly or in order after each other. Can be black and white or colored. Krita does not yet support all the parameters yet.

abr

Photoshop brush tip collections. We support many of the features of these brush files, though some advanced features are not supported yet.

Note that the definition of ABR brushes has been reverse engineered since Adobe does not make the specification public. We strongly recommend every Krita user to share brush tips in GBR and GIH format and more complex brushes as Krita presets.

All predefined brush tips are shown in one selector. There are four more options that influence the initial bitmap brush tip you start painting with:

Scale

Scales the brush tip. 1.0 is the native size of the brush tip. This can be fairly large! When painting with variable size (for instance governed by pressure), this is the base for the calculations.

Rotation

Initial rotation of the brush tip.

Spacing

Krita Gaussian Noise Reduction Device

Distance between the brush tip impressions.

Brush Mode¶

Alpha Mask

For colored brushes, don’t paint the actual colors, but make a grayscale brush tip that will be colored by your selected foreground/background color. Lighter areas will be interpreted as more transparent.

Color Image

Use the brush tip image exactly as it is. Especially useful for image stamps.

Lightness Map

New in version 4.3: Combines the features of Alpha Mask and Image Stamp modes. Transparency is preserved as it is in Image Stamp mode, but colors or gray tones in the brush are replaced by the foreground color. The Lightness values of the brush tip image (if thinking in HSL mode) are preserved, so dark parts of the image are dark, and bright parts are bright. This allows image stamps where you can choose the color, but preserve highlights and shadows, and can even create an effect of thick paint in a brush stroke by simulating the highlights and shadows caused by the texture of the paint and brush stroke (sometimes called an “impasto” effect).

There are three sliders here, to control the exact feel of the current brush tip in Lightness or Gradient mode:

Krita Gaussian Noise Reduction

Neutral point

This is the lightness level that will be the same as your current foreground color. Higher values than this will be lighter versions of the current foreground color, and lower, darker versions of the current color.

Brightness

Makes the tip as a whole brighter or darker.

Contrast
Reduction

Increase the contrast between dark and light areas in the tip.

Gradient Map

New in version 4.4: Use the lightness values of the brush tip image as a map to a gradient. Black maps to the left side of the gradient, and white to the right side of the gradient. The gradient used is the currently selected gradient in the main window, so you can change the gradient quickly and easily while painting. This mode allows image stamps with multiple colors that can be changed (great for flowers or other colorful vegetation), and can allow paint brushes that have multiple colors. Image adjustment sliders for Lightness Map mode can be used for this mode too.

Goal

In this chapter,

  • You will learn about Non-local Means Denoising algorithm to remove noise in the image.
  • You will see different functions like cv.fastNlMeansDenoising(), cv.fastNlMeansDenoisingColored() etc.

Theory

In earlier chapters, we have seen many image smoothing techniques like Gaussian Blurring, Median Blurring etc and they were good to some extent in removing small quantities of noise. In those techniques, we took a small neighbourhood around a pixel and did some operations like gaussian weighted average, median of the values etc to replace the central element. In short, noise removal at a pixel was local to its neighbourhood.

There is a property of noise. Noise is generally considered to be a random variable with zero mean. Consider a noisy pixel, (p = p_0 + n) where (p_0) is the true value of pixel and (n) is the noise in that pixel. You can take large number of same pixels (say (N)) from different images and computes their average. Ideally, you should get (p = p_0) since mean of noise is zero.

You can verify it yourself by a simple setup. Hold a static camera to a certain location for a couple of seconds. This will give you plenty of frames, or a lot of images of the same scene. Then write a piece of code to find the average of all the frames in the video (This should be too simple for you now ). Compare the final result and first frame. You can see reduction in noise. Unfortunately this simple method is not robust to camera and scene motions. Also often there is only one noisy image available.

So idea is simple, we need a set of similar images to average out the noise. Consider a small window (say 5x5 window) in the image. Chance is large that the same patch may be somewhere else in the image. Sometimes in a small neighbourhood around it. What about using these similar patches together and find their average? For that particular window, that is fine. See an example image below:

The blue patches in the image looks the similar. Green patches looks similar. So we take a pixel, take small window around it, search for similar windows in the image, average all the windows and replace the pixel with the result we got. This method is Non-Local Means Denoising. It takes more time compared to blurring techniques we saw earlier, but its result is very good. More details and online demo can be found at first link in additional resources.

For color images, image is converted to CIELAB colorspace and then it separately denoise L and AB components.

Image Denoising in OpenCV

OpenCV provides four variations of this technique.

Noise
  1. cv.fastNlMeansDenoising() - works with a single grayscale images
  2. cv.fastNlMeansDenoisingColored() - works with a color image.
  3. cv.fastNlMeansDenoisingMulti() - works with image sequence captured in short period of time (grayscale images)
  4. cv.fastNlMeansDenoisingColoredMulti() - same as above, but for color images.

Common arguments are:

  • h : parameter deciding filter strength. Higher h value removes noise better, but removes details of image also. (10 is ok)
  • hForColorComponents : same as h, but for color images only. (normally same as h)
  • templateWindowSize : should be odd. (recommended 7)
  • searchWindowSize : should be odd. (recommended 21)

Please visit first link in additional resources for more details on these parameters.

We will demonstrate 2 and 3 here. Rest is left for you.

1. cv.fastNlMeansDenoisingColored()

As mentioned above it is used to remove noise from color images. (Noise is expected to be gaussian). See the example below:

import cv2 as cv
dst = cv.fastNlMeansDenoisingColored(img,None,10,10,7,21)
plt.subplot(121),plt.imshow(img)
plt.show()

Below is a zoomed version of result. My input image has a gaussian noise of (sigma = 25). See the result:

2. cv.fastNlMeansDenoisingMulti()

Now we will apply the same method to a video. The first argument is the list of noisy frames. Second argument imgToDenoiseIndex specifies which frame we need to denoise, for that we pass the index of frame in our input list. Third is the temporalWindowSize which specifies the number of nearby frames to be used for denoising. It should be odd. In that case, a total of temporalWindowSize frames are used where central frame is the frame to be denoised. For example, you passed a list of 5 frames as input. Let imgToDenoiseIndex = 2 and temporalWindowSize = 3. Then frame-1, frame-2 and frame-3 are used to denoise frame-2. Let's see an example.

import cv2 as cv
img = [cap.read()[1] for i in range(5)]
# convert all to grayscale
gray = [cv.cvtColor(i, cv.COLOR_BGR2GRAY) for i in img]
Krita gaussian noise reduction
# convert all to float64
noise = np.random.randn(*gray[1].shape)*10
# Add this noise to images
noisy = [np.uint8(np.clip(i,0,255)) for i in noisy]
# Denoise 3rd frame considering all the 5 frames
dst = cv.fastNlMeansDenoisingMulti(noisy, 2, 5, None, 4, 7, 35)
plt.subplot(131),plt.imshow(gray[2],'gray')
plt.subplot(133),plt.imshow(dst,'gray')

Below image shows a zoomed version of the result we got:

It takes considerable amount of time for computation. In the result, first image is the original frame, second is the noisy one, third is the denoised image.

Additional Resources

  1. http://www.ipol.im/pub/art/2011/bcm_nlm/ (It has the details, online demo etc. Highly recommended to visit. Our test image is generated from this link)
  2. Online course at coursera (First image taken from here)

Krita Gaussian Noise Reduction Systems

Exercises