Professional Documents
Culture Documents
SPATIAL DOMAIN
M Lokanath
domain techniques
manipulation of image pixels
Frequency
domain techniques
Manipulation
an image
In Spatial domain
Where f(x,y) is the input image, g(x,y) is the processed image and T is an
operator on f.
Image negatives
Negative image
Log transformations
Contrast stretching
Assignment 1
Assignment 2
Write an M-function with the following specifications:
function H = imcircle(R, M, N)
%IMCIRCLE Generates a circle inside a rectangle.
% H = IMCIRCLE(R, M, N) generates a circle of radius R centered
% on a rectangle of height M and width N. H is a binary image with
% 1s on the circle and 0s elsewhere. R must be an integer >= 1.
Your program must check the validity of R and also it should check to
make sure that the specified circle fits in the given rectangle
dimensions. Use of for or while loops is not permitted.
Hint: Review function meshgrid and become familiar with function floor.
Assignment 2
Show the negative of these images
Matlab functions
Assignment
first solution
Written a function for generating
256x256 synthetic image
twodsin1.m
function f = twodsin1(A, uo, vo, M, N)
f=zeros(M, N);
for c =1:N
voy=vo *(c-1);
for r= 1:M
uox=uo *(r-1);
f(r,c)= A*sin(uox+voy);
end
end
Assignment
second solutions
A=[21 23 3i 4j 5+2i -12 0.45 -2.4 -4-3i ]
if ~isnumeric(A)
error('A must be a numeric array.');
end
if isa(A, 'double')
I = isfinite(A) & (imag(A) == 0) & (A ==
floor(A));
I = imag(A) == 0;
end
end
else
% to double.
if isreal(A)
I = true(size(A));
else
to thresholding
Other levels can be
suppressed or maintained
Useful for highlighting
features in an image,
Shape, to detect blockages.
Higher-order
[01000000]
[00100000]
[00001000]
[00000100]
[00000001]
Image Histograms
Frequencies
Grey Levels
Dark image
Bright image
Implementation of histogram
Histogram
equalization (linearization)
Histogram Equalisation
Spreading out the frequencies in an image (or
equalising the image) is a simple way to improve dark
or washed out images
sk T (rk )
The formula for histogram
equalisation is given where
k
rk:
input intensity
sk: processed intensity
k:
the intensity range
(e.g 0.0 1.0)
nj: the frequency of intensity j
MN: the sum of all frequencies
( L 1) pr (rj )
j 0
k
( L 1)
j 0
nj
MN
ASSIGNMENT 3
Question 1
For this image find
Histogram
Histogram
equalization of image
Histogram of processed image
Plot the transfer function.
Specified histogram
Question 2
Find for the given input image
Histogram
Histogram
equalization
Processed image histogram
Histogram specification
Specified image histogram
Assignment 2
first solution
function H = imcircle(R, M, N)
IMCIRCLE Generates a circle inside a rectangle.
H = IMCIRCLE(R, M, N) generates a circle of radius R centered
on a rectangle of height M and width N. H is a binary image with 1s on
the circle and 0s elsewhere. R must be an integer >= 1.
X0 = floor(M/2);
Y0 = floor(N/2);
if R > M - X0 - 1 | R > N - Y0 - 1
error('Circle does not fit in rectangle.')
end
if (floor(R) ~= R) | (R < 1)
Imshow(H);
Histogram matching(specification)
sk T (rk )
k
nj
j 0
rk
Pz (z) using
Vk G ( z k ) Pz ( zi ) sk
i 0
LOGIC OPERATIONS
IMAGE SUBTACTION
IMAGE AVERAGING
SPATIAL FILTERING
Spatial filtering
Basics
of spatial filtering
Smoothing spatial filters
Smoothing
linear filters
Order statistics filters
Sharpening
spatial filters
e
e
Image f (x, y)
Simply
1/
1/
Pixels
closer to the
central pixel are more
important
Often referred to as a
weighted averaging
1/
16
2/
16
1/
16
2/
16
4/
16
2/
16
1/
16
2/
16
1/
16
Weighted
averaging filter
Original Image
Smoothed Image
Thresholded Image
Median filter
Example
Original Image
With Noise
Image After
Averaging Filter
Image After
Median Filter
Remove
Sharpening
1st
filters
derivative filters
2nd derivative filters
Spatial Differentiation
Differentiation measures the rate of change of a
function
Lets consider a simple 1 dimensional example
Spatial Differentiation
st
1
Derivative
f
f ( x 1) f ( x)
x
st
1
Derivative (cont)
Image Strip
8
7
6
5
4
3
2
1
0
5 5 4 3 2 1 0 0 0 6 0 0 0 0 1 3 1 0 0 0 0 7 7 7 7
1st Derivative
0 -1 -1 -1 -1 0 0 6 -6 0 0 0 1 2 -2 -1 0 0 0 7 0 0 0
8
6
4
2
0
-2
-4
-6
-8
nd
2
Derivative
f
f ( x 1) f ( x 1) 2 f ( x)
2
x
nd
2
Derivative (cont)
Image Strip
8
7
6
5
4
3
2
1
0
5 5 4 3 2 1 0 0 0 6 0 0 0 0 1 3 1 0 0 0 0 7 7 7 7
-1 0 0 0 0 1 0 6
10
5
0
-5
-10
-15
-12 6
0 1
2nd0
Derivative
1 -4 1 1 0 0 7 -7 0 0
The Laplacian
The Laplacian is defined as follows:
f f
f 2 2
x
y
st
2
f
f ( x 1, y) f ( x 1, y) 2 f ( x, y)
2
x
2
f
f ( x, y 1) f ( x, y 1) 2 f ( x, y)
2
y
2
f [ f ( x 1, y) f ( x 1, y)
f ( x, y 1) f ( x, y 1)]
4 f ( x, y )
2
-4
Original
Image
Laplacian
Filtered Image
Laplacian
Filtered Image
Scaled for Display
g ( x, y) f ( x, y ) c[ f ( x, y)]
2
Laplacian
Filtered Image
Scaled for Display
Original
Image
=
Laplacian
Filtered Image
Sharpened
Image
g ( x, y) f ( x, y) f
f ( x, y) [ f ( x 1, y) f ( x 1, y)
f ( x, y 1) f ( x, y 1)
4 f ( x, y)]
5 f ( x, y) f ( x 1, y) f ( x 1, y)
f ( x, y 1) f ( x, y 1)
2
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
Gradient
Assignment 4.
problem 1. Local Histogram Equalization
The global histogram equalization technique is easily adaptable to local histogram equalization. The procedure is to
define a square or rectangular window (neighborhood) and move the center of the window from pixel to pixel. At each
location, the histogram of the points inside the window is computed and a histogram equalization transformation function
is obtained. This function is finally used to map the intensity level of the pixel centered in the neighborhood to create a
corresponding (processed) pixel in the output image. The center of the neighborhood region is then moved to an
adjacent pixel location and the procedure is repeated. Since only one new row or column of the neighborhood changes
during a pixel-to-pixel translation of the region, updating the histogram obtained in the previous location with the new
data introduced at each motion step is possible. This approach has obvious advantages over repeatedly computing the
histogram over all pixels in the neighborhood region each time the region is moved one pixel location.
Write an M-function for performing local histogram equalization. Your function should have the following specifications.
function g = localhisteq(f, m, n)
LOCALHISTEQ Local histogram equalization.
G = LOCALHISTEQ(F, M, N) performs local histogram equalization on input image F using a window of (odd) size M-by-N to
produce the processed image, G. To handle border effects, image F is extended by using the symmetric option in
function padarray. The amount of extension is determined by the dimensions of the local window. If M and N are
omitted, they default to 3. If N is omitted, it defaults to M. Both must be odd.
This function accepts input images of class uint8, uint16, or double. However, all computations are done using 8-bit
intensity values to speed-up computations. If F is of class double its values should be in the range [0 1]. The class of the
output image is the same as the class of the input.
Hint: Your code will be simplified if you use functions cumsum and tofloat. Keep in mind that only the intensity level of the
center of the neighborhood needs to be mapped at each location of the window.
Assignment 4 problem 2:
Experimenting with Larger Laplacian Masks
It is shown in class that the Laplacian mask w8 = [ 1, 1, 1; 1 8 1; 1, 1, 1]
yields a result sharper than the result with a similar mask with a 4 in the
center.
(a) Write an M-function that generates a Laplacian mask of arbitrary odd
size. Example, the mask of size 5 5 would consist of all 1s with a 24 in
the centre location.
(b) For the given image blurry_moon.tif. Compare the results obtained with
masks of size n x n for n = 3, 5, 9, 15, and 25
(c) Explain the differences in the resulting images.
Next class