Image Processing: Chapter (3) Part 2:intensity Transformation and Spatial Filters
Image Processing: Chapter (3) Part 2:intensity Transformation and Spatial Filters
Chapter(3)
Part 2:Intensity Transformation and
spatial filters
Hanan Hardan 1
Image Enhancement?
Hanan Hardan 2
Image Enhancement?
If we used 256 intensities of grayscale then:
- In dark image the most of pixels value <128
- In bright image the most of pixels value>128
Let x:old image
S:new image
S=x+c where c is constant value
>> S=imadd(x,50); -----------------brighter image
S=x-c where c is constant value
>> S=imsubtract(x,50); -------------darker image
We can add 2 image :
S=x+y (where x and y 2 image have same size)
Hanan Hardan 3
Image Enhancement Methods
s r
s= T(r)
Hanan Hardan 6
Intensity transformations functions
Hanan Hardan 7
Intensity transformations functions
Hanan Hardan 8
Basic intensity transformations
a) Linear ( negative and identity).
b) logarithmic ( Log and Inverse Log) .
c) Power( nth power and nth root).
Hanan Hardan 9
Hanan Hardan 10
Image Negatives (Negative Transformation)
s=L–1–r
Output gray level
Advantages of negative :
Produces an equivalent of a photographic negative.
Enhances white or gray detail embedded in dark regions.
Hanan Hardan 13
Image Negatives (Negative Transformation)
Hanan Hardan 14
Image Negatives (Negative Transformation)
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.
Image (r)
100 110 90 95
solution:
L= 28 = 256 98 140 145 135
89 90 88 85
s=L-1-r
102 105 99 115
s =255-r
Exercise:
Hanan Hardan 16
Image Negatives (Negative Transformation)
g = imcomplement (f);
Hanan Hardan 17
Log Transformations function
Hanan Hardan 18
Log Transformations function
Hanan Hardan 19
Log Transformations function
But this function changes the data class of the image to
double, so another sentence to return it back to uint8
should be done:
gs = im2uint8 (mat2gray(g));
Hanan Hardan 20
Log Transformations function
Example:
f g gs
Hanan Hardan 21
Inverse Logarithm Transformation
Do opposite to the log transformations
Used to expand the values of high pixels in
an image while compressing the darker-level
values.
Hanan Hardan 22
Logarithmic Transformations
InvLog Log
Hanan Hardan 23
Power-Law Transformations
Power-law(Gamma) transformations
have the basic form of:
s = c.rᵞ
Where c and ᵞ are positive constants
Map a narrow range of dark input
values into a wider range of output
values or vice versa
Hanan Hardan 24
Power-Law Transformations
Different transformation curves are
obtained by varying ᵞ (gamma)
Hanan Hardan 25
Power-Law Transformations
If gamma <1 :the mapping is weighted
toward brighter output values.
If gamma =1 (default):the mapping is
linear.
If gamma >1 :the mapping is weighted
toward darker output values.
Hanan Hardan 26
Power Law Example
Hanan Hardan 27
Power Law Example
Hanan Hardan 28
Power Law Example
Hanan Hardan 29
Power Law Example
Hanan Hardan 30
Power Law Example
•The images to the right
show a magnetic resonance
(MR) image of a fractured
human spine
•Different curves highlight
different detail
Hanan Hardan 31
Power Law Example
Hanan Hardan 32
Function imadjust
Function imadjust is the basic IPT tool for
intensity transformations of gray-scale
images. It has the syntax:
Hanan Hardan 33
Function imadjust
Hanan Hardan 36
Function imadjust
Example1:
Hanan Hardan 37
f g
Function imadjust
Example2:
f g
Hanan Hardan 38
Function imadjust
Example3:
f g
Hanan Hardan 39
Function imadjust
Example4:
f g
Hanan Hardan 40
Piecewise-Linear Transformation Functions
Principle Advantage: Some important
transformations can be formulated only as a
piecewise function.
Principle Disadvantage: Their specification
requires more user input that previous
transformations
Types of Piecewise transformations are:
Contrast Stretching
Gray-level Slicing
Bit-plane slicing
Hanan Hardan 41
Contrast Stretching
One of the simplest piecewise linear
functions is a contrast-stretching
transformation, which is used to enhance
the low contrast images.
Low contrast images may result from:
Poor illumination
Wrong setting of lens aperture during image
acquisition.
Hanan Hardan 42
Contrast Stretching
If T(r) has the form as shown in the figure below,
the effect of applying the transformation to every
pixel of f to generate the corresponding pixels in g
would:
Produce higher contrast than the original
image, by:
Darkening the levels below m in the original
image
Brightening the levels above m in the
original image
So, Contrast Stretching: is a simple image
enhancement technique that improves the
contrast in an image by ‘stretching’ the range of
intensity values it contains to span a desired
Hanan Hardan 43
range of values.
Contrast Stretching
(r2, s2)
(r1, s1)
Contrast stretching
Assume that
a: rmin,
b:rmax,
If r >180; s =255
T= If r <180 and r<90; s=T(r)
If r <90; s =0
darker
Hanan Hardan 46
Contrast Stretching
contrast stretching>
Contrast-Stretching Transformation
This equation is implemented in MATLAB for the
entire image as
Hanan Hardan 48
Contrast-Stretching Transformation
Example1:
>>g = 1 ./ (1+ (100 ./(double(f) + eps)) .^ 20);
>> imshow(f), figure, imshow(g);
Hanan Hardan 49
Contrast-Stretching Transformation
Example2:
>> g = 1 ./ (1+ (50 ./(double(f) + eps)) .^ 20);
>> imshow(f), figure, imshow(g);
Hanan Hardan 50
Contrast-Stretching Transformation
Example3:
>> g = 1 ./ (1+ (150 ./(double(f) + eps)) .^ 20);
>> imshow(f), figure, imshow(g);
Hanan Hardan 51
Thresholding
Contrast stretching:
(r1,s1)=(rmin,0) , (r2,s2)=(rmax,L-1)
Thresholding: (r1, s1)
(r1,s1)=(k,0) , (r2,s2)=(k,L-1)
Thresholding:
Hanan Hardan 53
Thresholding
Remember that:
Or
g(x,y) = T[f(x,y)]
Example: suppose m= 150 (called threshold),
s= T(r)
if r (or pixel intensity in image f ) الصورة االصليةis
above this threshold it becomes 1 in s (or pixel
intensity in image g ) الصورة بعد التعديل, otherwise it
Pixels above 150 become 1 becomes zero.
255
If f(x,y)>150; g(x,y)=1
T= If f(x,y)<150; g(x,y)=0
Or simply…
This is called
thresholding,
0 255
T= If r >150; s =1 and it produces
Hanan HardanIf r <150; s =0 a binary image!
54
Hanan Hardan 56
Application on Contrast stretching and thresholding
Thresholding function
(r1,s1)=(m,0) , (r2,s2)=(m,L-1)
m : meanHanan
intensity
Hardan
level in the image 57
Contrast Stretching
Figure 3.10(a) shows a typical transformation used for
contrast stretching. The locations of points (r1, s1) and (r2,
s2) control the shape of the transformation function.
If r1 = s1 and r2 = s2, the transformation is a linear
function that produces no changes in gray levels.
If r1 = r2, s1 = 0 and s2 = L-1, the transformation
becomes a thresholding function that creates a binary
image.
Intermediate values of (r1, s1) and (r2, s2) produce
various degrees of spread in the gray levels of the output
image, thus affecting its contrast.
In general, r1 ≤ r2 and s1 ≤ s2 is assumed, so the function
is always increasing.
Hanan Hardan 58
Contrast Stretching
Figure 3.10(b) shows an 8-bit image with low contrast.
Hanan Hardan 59
piecewise Linear transformation functions.
Exercise:
90 91 99 100
82 96 85 90
Hanan Hardan 60
solution in matlab:
function a2(x,s)
y=x;
[m n]=size(x);
for i=1:m
for j=1:n
if x(i,j)>= s
y(i,j)=255;
else y(i,j)=0;
end
end
end
figure, imshow(x);
figure, imshow(y);
Hanan Hardan 61