Image Processing-Ch3 Part 3
Image Processing-Ch3 Part 3
Chapter(3)
Part 3:Intensity Transformation and
spatial filters
Hanan Hardan 1
Gray-level Slicing
This technique is used to highlight a specific
range of gray levels in a given image.
– Similar to thresholding
– Other levels can be suppressed or maintained
– Useful for highlighting features in an image
It can be implemented in several ways, but the
two basic themes are:
One approach is to display a high value for all
gray levels in the range of interest and a low value
for all other gray levels.
The second approach, based on the
transformation brightens the desired range of gray
levels but preservesHanan
gray levels unchanged.
Hardan 2
Gray-level Slicing
Hanan Hardan 4
Gray-level Slicing: approach 1
Hanan Hardan 5
Gray-level Slicing: approach 1
Solution:
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);
Hanan Hardan 6
Gray-level Slicing: approach 2
Hanan Hardan 7
Gray-level Slicing: approach 2
Solution:
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)=x(i,j);
end
end
end
figure, imshow(x);
figure, imshow(y);
Hanan Hardan 8
Gray-level Slicing
Homework
example: apply intensity level slicing (approch2) in Matlab to
read moon image , then If the pixel intensity in the old image
is between (0 20) convert it in the new image into 130.
Hanan Hardan 9
Bit-plane Slicing
Pixels are digital numbers, each one composed of
bits. Instead of highlighting gray-level range, we
could highlight the contribution made by each bit.
This method is useful and used in image
compression.
Hanan Hardan 11
Bit-plane Slicing
Often by isolating particular
bits of the pixel values in an
image we can highlight
interesting aspects of that
image
– Higher-order bits usually
contain most of the
significant visual
information
– Lower-order bits contain
subtle details
Hanan Hardan 12
Bit-Plane Slicing
Hanan Hardan 13
Bit-plane Slicing
Hanan Hardan 14
Bit-Plane Slicing
Hanan Hardan 15
Bit-plane Slicing(example)
100
01100100
Hanan Hardan 16
Bit-plane Slicing- programmed
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);
Hanan Hardan 17
Histogram Processing
What is a Histogram?
In Statistics, Histogram is a graphical
representation showing a visual
impression of the distribution of data.
An Image Histogram is a type of
histogram that acts as a graphical
representation of the lightness/color
distribution in a digital image. It plots the
number of pixels for each value.
Hanan Hardan 18
Histogram?
The histogram of a digital image with gray
levels in the range [0, L-1] is a discrete
function:
h(rk) = nk
Where:
rk : kth gray level
nk : # of pixels with having gray level rk
Hanan Hardan 19
Image Histogram
Hanan Hardan 20
Histogram Processing
It is common practice to normalize a
histogram by dividing each of its values by
the total number of pixels in the image,
denoted by n. Thus, a normalized
histogram is given by
p(rk) = nk / n, for k = 0, 1, …, L -1.
Thus, p(rk) gives an estimate of the
probability of occurrence of gray level rk.
Note that the sum of all components of a
normalized histogram is equal to 1.
Hanan Hardan 21
Why Histogram?
Histograms are the basis for numerous
spatial domain processing techniques
Histogram manipulation can be used
effectively for image enhancement
Histograms can be used to provide useful
image statistics
Information derived from histograms are
quite useful in other image processing
applications, such as image compression
and segmentation.
Hanan Hardan 22
Histogram of the image:
histogram
Hanan Hardan 24
Histogram of the image:
low contrast image
high-contrast image
Hanan Hardan 26
Histogram in MATLAB
We obtain the normalized histogram simply by using the
expression.
Hanan Hardan 27
Other ways to display Histograms
Consider an image f. The simplest way to plot its histogram
is to use imhist with no output specified:
>> imhist (f);
Figure 3.7(a) shows the result.
Hanan Hardan 28
Other ways to display Histograms
A stem graph
A bar graph
A Plot graph
>> h = imhist(f);
>> bar (h);
>> plot (h);
>> stem (h);
Hanan Hardan 29
Histogram equalization of the image:
We have this image in matlab called
pout.tif, when we plot its histogram it
is showed like this:
Hanan Hardan 30
Histogram equalization of the image:
histogram equalization :
is the process of adjusting intensity values of pixels.
The process which increases the dynamic range of the gray
level in a law contrast image to cover full range of gray
levels.
Im matlab : we use histeq function
Histogram
produces
pixels having
values that are
distributed
throughout
the range
Hanan Hardan 31
Histogram equalization of the image:
Notice that histogram
equalization does not
always produce a
good result
Hanan Hardan 32
Equalization (mathematically)
g(x) = (L/n). T(X) -1
Where,
G(X) : the new image after equalization
L: No of gray levels 2n
n: No of pixels
T(x): cumulative sum of each gray level
Hanan Hardan 33
Equalization (mathematically)
L عدد البكسل لكلX مجموع تراكميT(X) G(x)
grayl Graylevel للبكسل Assume that we have
evels (3bits per pixels) or 8
levels of grayscale,
0 1 1 0 and we want to
equalize the following
1 3 4 0 image example.
2 5 9 1
3 6 15 2 G(x)=(L/n). T(X) -1
=(8/32). T(x) -1
4 6 21 4
5 6 27 5
6 2 29 6
7 3 32 7
8 عدد ال
عدد البكسالت الكليNo of pixels
Hanan Hardan 34
graylevel