You are on page 1of 35

Digital Image Processing

Dr. M. Ilyas Fakhir

Lecture-4
The
2
of
Basic of Intensity Transformation &
36
Spatial Filtering
 The spatial domain processes we discuss in this chapter are
based on the expression g(x, y) = T[f(x, y)]
where f (x, y) is an input image, g (x, y) is the output image, and T is
an operator on f defined over a neighborhood of point (x, y).
 The operator can be applied to the
pixels of a single image or to the pixels
of a set of images, such as performing
the elementwise sum of a sequence
of images for noise reduction.
The point (x0 , y0) shown is an arbitrary
location in the image, and the small region
shown is a neighborhood of (x0 , y0).
The
3
of
Basic of Intensity Transformation &
36
Spatial Filtering
 The smallest possible neighborhood is of size 1 × 1 . In this case, g depends only on
the value of f at a single point (x, y) and T becomes an intensity (also called a gray-
level, or mapping) transformation function of the form: s = T(r)

 Intensity transformation functions.


(a) Contrast stretching function. (b) Thresholding function.
The
4
of
Basic of Intensity Transformation &
36
Spatial Filtering
5
of
Some Basic Intensity Transformation
36
Functions
 Image Negatives:
 The negative of an image with intensity levels in the range [0 , L - 1 ] is
obtained by using the negative transformation function shown in Fig., which
has the form:
s=L-1-r

 The negative transformation is suitable for enhancing white or gray


detail embedded in dark regions of an image, especially when the
black area are dominant in size.
6
of
Some Basic Intensity Transformation
36
Functions
 Image Negatives:
 Example 1:
the following matrix represents the pixels
values of an 8-bit image (r) , apply negative
transform and find the resulting image pixel
values.
solution:
L= 28 = 256
s=L-1-r
s =255-r
Apply this transform to
each pixel to find the negative
7
of
Some Basic Intensity Transformation
36
Functions
 Image Negatives:
 Exercise:
the following matrix represents the pixels values of a
5-bit image (r) , apply negative transform and find
the resulting image pixel values.
solution:
8
of
Some Basic Intensity Transformation
36
Functions
 Log Transformations:
 The general form of the log transformation is s = c log (1 + r)
Where c is constant, and it is assumed that r ≥ 0.
 Log curve maps a narrow range of low gray-level values
in the input image into a wider range of the output
levels.
 Used to expand the values of dark pixels in an image
while compressing the higher-level values.
 It compresses the dynamic range of images with large
variations in pixel values.
 Log functions are particularly useful when the input grey
level values may have an extremely large range of
values
9
of
Some Basic Intensity Transformation
36
Functions
 Log Transformations:
 The general form of the log transformation is s = c log (1 + r)
Where c is constant, and it is assumed that r ≥ 0.

(a) Fourier spectrum displayed as a grayscale image. (b) Result of applying the log transformation with c = 1. Both
images are scaled to the range [0, 255].
10
of
Some Basic Intensity Transformation
36
Functions
 Inverse Log Transformations:
 Do opposite to the log transformations
 Used to expand the values of high pixels in an image while
compressing the darker-level values.
11
of
Some Basic Intensity Transformation
36
Functions
 Power-law (Gamma) Transformations:
 The general form of the power-law transformations has the for s = crᵧ
Where c and are positive constants.
 Plots of the gamma equation
s = cr for various values of
(c = 1 in all cases). Each
curve was scaled
independently so that all
curves would fit in the
same graph. Our interest
here is on the shapes of
the curves, not on their
relative values.
The process used to correct
these power-law response
phenomena is called gamma correction or gamma encoding.
12
of
Some Basic Intensity Transformation
36
Functions
 Power-law (Gamma) Transformations:
 (a) Intensity ramp image.
(b) Image as viewed on a
simulated monitor with a
gamma of 2.5. (c) Gamma
corrected image.
(d) Corrected image as
viewed on the same monitor.
Compare (d) and (a).
13
of
Some Basic Intensity Transformation
36
Functions
 Power-law (Gamma)
Transformations:
 (a) Magnetic resonance
image (MRI) of a fractured
human spine (the region
of the fracture is enclosed by
the circle).
(b)–(d) Results of applying the
transformation with c = 1 and
= 0.6, 0.4, and 0.3,
respectively.
14
of
Some Basic Intensity Transformation
36
Functions
 Power-law (Gamma) Transformations:
 Map a narrow range of dark input values into a wider
range of output
values or vice versa
 If <1 :the mapping is weighted toward brighter
output values.
 If =1 (default):the mapping is linear.
 If >1 :the mapping is weighted toward darker
output values.
15
of
Some Basic Intensity Transformation
36
Functions
 Power-law Example:
 (a) Aerial image.
(b)–(d) Results
of applying the
transformation
with = 3.0, 4.0,
and 5.0, respectively.
16
of
36
Function imadjust
 Function imadjust is the basic IPT tool for intensity
transformations of gray-scale images. It has the
syntax:

g = imadjust (f, [low_in high_in], [low_out high_out], gamma)


17
of
36
Function imadjust
 Example1:
 >> f = imread ('baby-BW.jpg');
>> g = imadjust (f, [0 1], [1 0]);
>> imshow(f), figure, imshow(g);

 This Obtaining the negative image


18
of
36
Function imadjust
 Example2:
 >> f = imread ('baby-BW.jpg');
>> g = imadjust (f, [0.5 0.5], [1 0], 0.5);
>> imshow(f), figure, imshow(g);
19
of
36
Function imadjust
 Example3:
 >> f = imread ('baby-BW.jpg');
>> g = imadjust (f, [0.75 0.75], [0.6 1], 0.5);
>> imshow(f), figure, imshow(g);
20
of
36
Function imadjust
 Example4:
 >> f = imread ('baby-BW.jpg');
>> g = imadjust (f, [], [], 2);
>> imshow(f), figure, imshow(g);
21
of
Some Basic Intensity Transformation
36
Functions
 Piecewise-Linear Transformation Functions:
 These functions, as the name suggests, are not entirely
linear in nature. However, they are linear between certain x-
intervals. One of the most commonly used piecewise-linear
transformation functions is contrast stretching. Contrast
stretching expands the range of intensity levels in an image
so that it spans the ideal full intensity range of the recording
medium or display device.

Contrast = (Imax - Imin)/(Imax + Imin)


22
of
Some Basic Intensity Transformation
36
Functions
 Contrast stretching.
(a) Piecewise linear
transformation function.
(b) A low-contrast
electron microscope
image of pollen,
magnified 700 times.
(c) Result of contrast
stretching, obtained by
setting (r1 , s1) = (rmin , 0)
and (r2 , s2) = (rmax , L – 1)
(d) Result of thresholding,
with (r1 , s1) = (m , 0) and
(r2 , s2) = (m , L – 1), m is
the mean intensity level
in the image.
23
of
Some Basic Intensity Transformation
36
Functions
 Example: in the graph, suppose we have the
following intensities : a=90, b=180, m=100
 if r is above 180 ,it becomes 255 in s.
 If r is below 90 , it becomes 0,
 If r is between 90, 180 , T applies as follows:
when r < 100 , s closes to zero (darker)
when r > 100 , s closes to 255 (brighter)

 (a = rmin b = rmax)

 This is called contrast stretching, which means that the bright pixels in the
a m b
image will become brighter and the dark pixels will become darker, this
means : higher contrast image.
24
of
Some Basic Intensity Transformation
36
Functions
 Thresholding: Is a limited case of contrast stretching, it produces a
two-level (binary) image. Pixels above 150
 Assume that
 a = rmin
 b = rmax
 K = intensity

 Example: suppose k= 150 (called threshold)

if r > 150; s = 1
T=
if r < 150; s =0
Pixels less than 150
25
of
Some Basic Intensity Transformation
36
Functions
 Thresholding:

 Pixels above threshold is considered bright and below it is considered dark, and this
process is called thresholding.
26
of
Some Basic Intensity Transformation
36
Functions
 Exercise:
The following matrix represents the pixels values of an 8-bit
image (r) , apply thresholding transform assuming that the
threshold m=95, find the resulting image pixel values.
 Solution:
27
of
Some Basic Intensity Transformation
36
Functions
 Intensity-Level Slicing (Grey-Level Slicing:
 There are applications in which it is of interest to highlight a specific range of intensities in an image.
 Some of these applications include enhancing features in satellite imagery, such as masses of water, and
enhancing flaws in X-ray images.

 (a) This transformation function highlights range [A , B] and reduces all other intensities to a lower level. (b) This function
highlights range [A , B] and leaves other intensities unchanged.
28
of
Some Basic Intensity Transformation
36
Functions
 Intensity-Level Slicing:

 (a) Aortic angiogram. (b) Result of using a slicing transformation of the type illustrated in Fig. slide 11(a), with the range of
intensities of interest selected in the upper end of the gray scale. (c) Result of using the transformation in Fig. slide 11(b), with
the selected range set near black, so that the grays in the area of the blood vessels and kidneys were preserved.
29
of
Some Basic Intensity Transformation
36
Functions
 Example: Apply intensity level slicing to read cameraman image , then If
the pixel intensity in the old image is between (100  200) convert it in the
new image into 255 (white). Otherwise convert it to 0 (black).
30
of
Some Basic Intensity Transformation
36
Functions
 Example: Apply intensity level slicing to read cameraman image , then If
the pixel intensity in the old image is between (100  200) convert it in the
new image into 255 (white). Otherwise convert it to 0 (black).
 Solution (Matlab):
x=imread('cameraman.tif');
y=x;
[w h]=size(x);
for i=1:w
for j=1:h
if x(i,j)>=100 && x(i,j)<=200 y(i,j)=255;
else y(i,j)=0;
end
end
end
figure, imshow(x);
figure, imshow(y);
31
of
Some Basic Intensity Transformation
36
Functions
 Bit-Plane Slicing:
 Pixel values are integers composed of bits. For example, values in a 256-
level grayscale image are composed of 8 bits (one byte).
 As Fig. illustrates, an 8-bit image may be considered as being composed
of eight one-bit planes, with plane 1 containing the lowest-order bit of all
pixels in the image, and plane 8 all the highest-order bits.
32
of
Some Basic Intensity Transformation
36
Functions
 Bit-Plane Slicing:
 (a) An 8-bit gray-scale image of size 550 × 1192 pixels. (b) through (i) Bit
planes 8 through 1, with bit plane 1 corresponding to the least significant
bit. Each bit plane is a binary image.
33
of
Some Basic Intensity Transformation
36
Functions
 Bit-Plane Slicing:
 (a) An 8-bit gray-scale image of size 550 × 1192 pixels. (b) through (i) Bit
planes 8 through 1, with bit plane 1 corresponding to the least significant
bit. Each bit plane is a binary image.
34
of
Some Basic Intensity Transformation
36
Functions
 Example:
 We have to use bit get and bit set to extract 8 images;
01100100

35
of
Some Basic Intensity Transformation
36
Functions
 Example: Apply bit-plane slicing in Matlab to read cameraman
image , then extract the image of bit 6.
Solution:

x=imread('cameraman.tif');
y=x*0;
[w h]=size(x);
for i=1:w
for j=1:h
b=bitget(x(i,j),6);
y(i,j)=bitset(y(i,j),6,b);
end
end
figure, imshow(x);
figure, imshow(y);

You might also like