You are on page 1of 33

Image Processing,

Retrieval, and Analysis (I)


Prof. Christian Bauckhage
Outline
Lecture 18

Fun With Gaussian Smoothing

Summary
Fun With Gaussian Smoothing

Gaussian glow

f g h = α f + (1 − α)g
Fun With Gaussian Smoothing

Gaussian glow, σ ∈ {2.5, 5.0, 7.5}, α ∈ {0.7, 0.8, 0.9}


Fun With Gaussian Smoothing

Gaussian glow
I python code
import scipy.misc as msc
import scipy.ndimage as img

f = 1. * msc.imread(’input.png’)

g = img.filters.gaussian_filter(f, sigma=s)

h = a * f + (1.-a) * g

msc.toimage(h, cmin=0, cmax=255).save(’output.png’)


Fun With Gaussian Smoothing

Gaussian glow, interesting effect for α > 1 (e.g. α = 4)

f g h = α f + (1 − α)g
Fun With Gaussian Smoothing

Gaussian edge glow

f g h = f + α g, α = 6
Fun With Gaussian Smoothing

Gaussian edge glow


I python code
import scipy.misc as msc
import scipy.ndimage as img

f = 1. * msc.imread(’input.png’)

g = img.filters.gaussian_gradient_magnitude(f, sigma=s)

h = f + a * g

msc.toimage(h, cmin=0, cmax=255).save(’output.png’)


Fun With Gaussian Smoothing

Gaussian radioactive edge glow


Fun With Gaussian Smoothing

Gaussian radioactive edge glow


I python code
import scipy.misc as msc
import scipy.ndimage as img

f = 1. * msc.imread(’input.png’)

g = img.filters.gaussian_gradient_magnitude(f, sigma=s)

R = f
G = f + a * g
B = f

h = np.array([R, G, B])

msc.toimage(h, cmin=0, cmax=255).save(’output.png’)


Fun With Gaussian Smoothing

image aging

original smoothed noise added sepia toning


Fun With Gaussian Smoothing

image aging
I python code
import numpy as np
import scipy.ndimage as img

y,x = f.shape

# first blur, then add noise


g = img.filters.gaussian_filter(f, sigma=simgasmooth)
h = g + np.random.randn(y,x) * sigmanoise

# sepia toning
m = h.mean() # average intensity in image h
R = (162-m) + h # set average red to 162
G = (138-m) + h # set average green to 138
B = (101-m) + h # set average blue to 101
Fun With Gaussian Smoothing

angular Gaussian blur

f (x, y) F(r, ϕ) blur along ϕ axis


Fun With Gaussian Smoothing

angular Gaussian blur

f (x, y) F(r, ϕ) blur along ϕ axis g(x, y)


Fun With Gaussian Smoothing

radial Gaussian blur

f (x, y) F(r, ϕ) blur along r axis


Fun With Gaussian Smoothing

radial Gaussian blur

f (x, y) F(r, ϕ) blur along r axis g(x, y)


Fun With Gaussian Smoothing

angular Gaussian blur

f (x, y) g(x, y)
Fun With Gaussian Smoothing

radial Gaussian blur

f (x, y) g(x, y)
Fun With Gaussian Smoothing

angular and radial Gaussian blur


I python code
...
Fun With Gaussian Smoothing

DoG for blob detection


Fun With Gaussian Smoothing

DoG for blob detection


Fun With Gaussian Smoothing

DoG for blob detection


I python code
import numpy as np
import scipy.ndimage as img

sigs = np.array([1.2, 1.4, 1.6, 1.8, 2.0,


2.4, 2.8, 3.2, 3.6, 4.0,
4.8, 5.6, 6.4, 7.2, 8.0]) * 5.

# compute list of Gaussian blurred images


imgs = []
for s in sigs:
g = img.filters.gaussian_filter(f, s, ’constant’, cval=255)
imgs.append(g)

# compute list of DoG images


dogs = []
for i in range(len(imgs)-1):
d = (imgs[i] - imgs[i+1])
dogs.append(d)
Fun With Gaussian Smoothing

DoG for blob detection


I python code (cont.)

# turn list of DoG images into 3D array


stack = np.array(dogs)

# determine local minima and maxima (i.e. keypoints)


maxvals = img.maximum_filter(stack, 3)
minvals = img.minimum_filter(stack, 3)

maxima = (stack == maxvals)


minima = (stack == minvals)

# determine array indices (i.e. locations) of keypoints


kpinds = np.where((maxima==True) | (minima==True))
Fun With Gaussian Smoothing

DoG for detecting focus objects


Fun With Gaussian Smoothing

DoG for detecting focus objects

greyscale image
Fun With Gaussian Smoothing

DoG for detecting focus objects

greyscale image DoG, σ1 = 0.5, σ2 = 1.0


Fun With Gaussian Smoothing

DoG for detecting focus objects

greyscale image DoG, σ1 = 0.5, σ2 = 1.0

non-maximum suppression
Fun With Gaussian Smoothing

DoG for detecting focus objects

greyscale image DoG, σ1 = 0.5, σ2 = 1.0

non-maximum suppression morphological hole filling


Fun With Gaussian Smoothing

DoG for detecting focus objects


I python code
# convert color image f to grey scale image h
R, G, B = f[:,:,0], f[:,:,1], f[:,:,2]
h = 0.2989 * R + 0.5870 * G + 0.1140 * B

# compute DoG image k


i = img.filters.gaussian_filter(h, sigma=0.5, mode=’reflect’)
j = img.filters.gaussian_filter(h, sigma=1.0, mode=’reflect’)
k = i-j

# suppress small values in k and turn it into binary image


k = np.abs(k)
k[k < 0.1 * k.max()] = 0
k[k > 0] = 1

# apply morphology
l = img.morphology.binary_dilation(k)
m = img.morphology.binary_fill_holes(l)
Fun With Gaussian Smoothing

DoG for detecting focus objects


I python code (cont.)
# mask out focus object
R = R * m
G = G * m
B = B * m

# final result
g = np.array([R, G, B])
Fun With Gaussian Smoothing

DoG for detecting focus objects


Fun With Gaussian Smoothing

DoG for detecting focus objects


Summary

we now know about


I practical applications of Gaussian smoothing

You might also like