0% found this document useful (0 votes)
10 views31 pages

Lecture-4 (Image Enhancement)

Uploaded by

eisha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views31 pages

Lecture-4 (Image Enhancement)

Uploaded by

eisha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

Spatial Filtering and Image

Enhancement
 Image Enhancement, - Bit-Place Slicing,
- Spatial domain, Histogram processing,
- Frequency domain. - dark image, bright image,
 Basic Gray level transformation, low contrast.
- Image Negative, - histogram equalization,
- Log transformations, - histogram matching,
- Power-Law transformation, - histogram statistics for
 Piecewise-linear transform image enhancement,
functions, - local enhancement.
- Contrast Stretching,
- Gray-level Slicing,

@Copyrights: Digital Image Processing Organized by Dr. Ahmad Jalal (http://portals.au.edu.pk/imc/)


1. Image Enhancement in the Spatial Domain
 Enhancement is the process of an image in which;
- the result is more suitable than the original image.
 Image enhancement approaches fall into 2 broad categories.

(1) Spatial Domain:


- refers to the image plane itself and approaches in this category are based on
direct manipulation of pixels in an image. OR
- image plane itself, directly process the intensity values of the image plane.

(2) Frequency domain:


- are based on modifying the transform of an image. OR
- process the transform coefficients, not directly process the intensity values of
the image plane.

@Copyrights: Digital Image Processing Organized by Dr. Ahmad Jalal (http://portals.au.edu.pk/imc/)


1. Image Enhancement in the Spatial Domain
 Spatial domain refers to the aggregate of pixels composing in an
image.
- operate directly on these pixels.
 Spatial domain processed will be denoted by the expression as:
g (x,y) = T [ f (x,y) ]

–where f (x, y) is the input image, g (x, y) is the processed image and T is an
operator on f, defined over some neighborhood of (x, y).

–Enhancement at any point in an image depends only on the gray level at that
point, technique in this category are refereed to as point processing.
For Example:
–While mask coefficient determine the nature of the process, such as
Image sharpening.
- Enhancement techniques also based on this type of approach often are
refereed to as mask processing or filtering.
@Copyrights: Digital Image Processing Organized by Dr. Ahmad Jalal (http://portals.au.edu.pk/imc/)
2. Basic Gray (intensity) Level Transformation
 Spatial Domain Procedures. s= spatial transform
 Gray level contains; r= gray level
- Brightness of a pixel.
- Lighting from black to white values from 0 (i.e, being black) to 255 (i.e, being
white) .

 4 basic types of functions used frequently for image enhancement.


(1) Image Negative:
– The image of an image with gray levels in the range [ 0, L-1] is obtained by
using negative transform.
Image negatives
s  L 1  r
– Reversing the intensity level.
– Enhancing white or gray details embedded in
dark regions of an image, if black areas are dominant.
@Copyrights: Digital Image Processing Organized by Dr. Ahmad Jalal (http://portals.au.edu.pk/imc/)
2. Basic Gray (intensity) Level Transformation
(2) Log Transformation:
– The general form of the log transformation
Log Transformations
s  c log(1  r )
– This transformation maps a narrow range of low gray-level in the input
image into a wider range of output levels.
– Important characteristics that; it compresses the dynamic range of images
with large variations in pixel values.

@Copyrights: Digital Image Processing Organized by Dr. Ahmad Jalal (http://portals.au.edu.pk/imc/)


2. Basic Gray (intensity) Level Transformation
(3) Power-Law Transformation:
Power-law transformations have the basic form

s  cr
where c and are positive constants.
–Power-law curves with fractional values of map, a narrow range of dark
input values into a wider range of output values.
For Example:
–A variety of devices used for image
capture, printing and display response
according to a power law.

-The exponent in the power-law equation


is referred as gamma.
-The process used to correct this power-
Law response called gamma-correction.
@Copyrights: Digital Image Processing Organized by Dr. Ahmad Jalal (http://portals.au.edu.pk/imc/)
2. Basic Gray (intensity) Level Transformation

(3) Power-Law Transformation:


For Example: Cathode ray tube (CRT)
devices have an intensity-to-voltage
response that is a power function, with
exponents varying from approximately
1.8 to 2.5.

Another Example, Gamma correction in


this case is straightforward. All we use to image

do is preprocess the input image before Monitor

inputting it to the monitor by performing Correction


Gamma

the transformation. Monitor

S = r 1/2.5 = r 0.4
@Copyrights: Digital Image Processing Organized by Dr. Ahmad Jalal (http://portals.au.edu.pk/imc/)
Example: Power-Law Transformation

@Copyrights: Digital Image Processing Organized by Dr. Ahmad Jalal (http://portals.au.edu.pk/imc/)


2. Basic Gray (intensity) Level Transformation
(4) Piecewise-Linear Transformations

(a) Contrast Stretching:


 Expands the range of intensity levels in
an image so that it spans the full
intensity range of the recording
medium or display device.
 Low-contrast images can result from
poor illumination.
- lack of dynamic range in the imaging sensor or
even wrong setting of the lens.

 Idea behind contrast stretching is;


- to increase the dynamic range of the gray
levels in the image being processed.

@Copyrights: Digital Image Processing Organized by Dr. Ahmad Jalal (http://portals.au.edu.pk/imc/)


2. Basic Gray (intensity) Level Transformation
(4) Piecewise-Linear Transformations

(a) Contrast Stretching:


- Intermediate values of ( r1, s1) and (r2, s2) produces various degrees of
spread in the gray levels of the output image ,thus affecting its contrast.

setting (r1, s1) = (rmin, 0) and (1)


(r2, s2) = (rmax, L-1) (2)

where rmin and rmax denote the minimum and maximum gray levels in the
image.

@Copyrights: Digital Image Processing Organized by Dr. Ahmad Jalal (http://portals.au.edu.pk/imc/)


2. Basic Gray (intensity) Level Transformation
(4) Piecewise-Linear Transformations
(b) Gray(Intensity)-level Stretching:
- Highlighting a specific range of intensities in an image often is of interest.
- Applications include enhancing features such as enhancing flaws in X-ray
images.

Highlight the major


blood vessels and
study the shape of the
flow of the contrast
medium (to detect
blockages, etc.)
Measuring the
actual flow of the
contrast medium as
a function of time in
a series of images
@Copyrights: Digital Image Processing Organized by Dr. Ahmad Jalal (http://portals.au.edu.pk/imc/)
2. Basic Gray (intensity) Level Transformation
(4) Piecewise-Linear Transformations
(c) Bit-Plane Slicing:
 Highlighting the contribution made to total image appearance by
specified bits might be desired.

For Example:
- 0 for the least significant bit
- 7 for the most significant bit

@Copyrights: Digital Image Processing Organized by Dr. Ahmad Jalal (http://portals.au.edu.pk/imc/)


2. Basic Gray (intensity) Level Transformation
(4) Piecewise-Linear Transformations

(c) Bit-Plane Slicing:


 processing the input image with a thresholding gray-level
transformation function.

1) Maps all levels in the image between 0 to 127 to one level.


2) Maps all levels between 129 to 255 to another.

@Copyrights: Digital Image Processing Organized by Dr. Ahmad Jalal (http://portals.au.edu.pk/imc/)


2. Basic Gray (intensity) Level Transformation

@Copyrights: Digital Image Processing Organized by Dr. Ahmad Jalal (http://portals.au.edu.pk/imc/)


2. Basic Gray (intensity) Level Transformation
(Hands-on Practices-Hour)
1) Image Negative 2) Log Transformations
a = imread('text.png'); a=imread('Penguins.jpg')
[m,n] = size(a); subplot(2,2,1)
for i=1:1:m imshow(a);
for j=1:1:n title 'Original Image'
Original Image
b(i,j) = 255-a(i,j); b=im2double(a)
end s=(1*log(1+b))*256;
end s1=uint8(s)
subplot (1,2,1),subimage(a),title(‘Original subplot(2,2,2)
Image’); imshow(s1);
subplot (1,2,2),subimage(b),title(‘Negative title ‘log=1'
log=1
Image’); sp=(2*log(1+b))*256;
s2=uint8(sp)
subplot(2,2,3)
imshow(s2);
title 'log=2' log=2
sp2=(3*log(1+b))*256;
s3=uint8(sp2)
subplot(2,2,4)
imshow(s3);
Original Image Negative Image
title 'log=3
log=3
@Copyrights: Digital Image Processing Organized by Dr. Ahmad Jalal (http://portals.au.edu.pk/imc/)
2. Basic Gray (intensity) Level Transformation
(Hands-on Practices-Hour)
3) Power-Law Transformation 4) Piecewise-Linear Transformations
c=1; (Contrast Stretching)
Gamma=input('Enter the Gamma values = '); % program to increase the contrast of an image
x=imread('remote.jpg'); x= input(‘Enter the factor which contrast should be
x1=double(x); increased’);
y=c*(x1.^Gamma(1)); % s=c*(r^ γ)
y1=c*(x1.^Gamma(2));
a = imread (‘clown.png’);
y2=c*(x1.^Gamma(3)); [m,n] = size(a);
for i = 1:1:m
subplot(141),imshow(x), title('Aerial image') for j=1:1:n
subplot(142),imshow((y),[]), title(‘Image(Gamma=1)') b(i,j) = a(I,J)*x;
subplot(143),imshow((y1),[]), title(‘Image(Gamma=2)') end
subplot(144),imshow((y2),[]), title(‘Image(Gamma=3)')
end
subplot (1,2,1),subimage(a),title(‘Original Image’);
subplot (1,2,2),subimage(b),title(‘contrast Image’),
xlabel(sprintf(‘Contrast increased by a factor of %g’,x));

Aerial image

?
‘Image(Gamma=1)’

‘Image(Gamma=2)’ ‘Image(Gamma=3)’ Original Image contrast Image


@Copyrights: Digital Image Processing Organized by Dr. Ahmad Jalal (http://portals.au.edu.pk/imc/)
2. Basic Gray (intensity) Level Transformation
(Hands-on Practices-Hour)
5) Piecewise-Linear Transformations
(Gray(Intensity)-level Stretching)

i=imread('kidney.tif'); % should be graylevel image Original Image

j=double(i);
k=double(i);
[row,col]=size(j);
T1=input('Enter the Lowest threshold value:');
T2=input('Enter the Highest threshold value:');
for x=1:row
for y=1:col
if((j(x,y)>T1) && (j(x,y)<T2)) Graylevel slicing with background Graylevel slicing without background
j(x,y)=i(x,y);
k(x,y)=255;
else
j(x,y)=0;
k(x,y)=0;
end
end
end

@Copyrights: Digital Image Processing Organized by Dr. Ahmad Jalal (http://portals.au.edu.pk/imc/)


2. Basic Gray (intensity) Level Transformation
(Hands-on Practices-Hour)
6) Piecewise-Linear Transformations
(Bit-Plane Slicing)
clear all; close all; clc;
I = imread('moon.tif'); figure,imshow(I); title('original'); impixelinfo;
II = double(I);
plane1.LSB plane2 plane3 plane4
%---Slice into bit planes
c0 = mod(II, 2); c1 = mod(floor(II/2), 2);
c2 = mod(floor(II/4), 2); c3 = mod(floor(II/8), 2);
c4 = mod(floor(II/16), 2); c5 = mod(floor(II/32), 2);
c6 = mod(floor(II/64), 2);
c7 = mod(floor(II/128), 2);
%---display planes
figure; plane5 plane6 plane7 Plane8. MSB
sr = 2; sc = 4; si = 1;
subplot(sr, sc, si);si=si+1; imshow(c0); title('plane1. LSB');
subplot(sr, sc, si);si=si+1; imshow(c1); title('plane2');
subplot(sr, sc, si);si=si+1; imshow(c2); title('plane3');
subplot(sr, sc, si);si=si+1; imshow(c3); title('plane4');
subplot(sr, sc, si);si=si+1; imshow(c4); title('plane5');
subplot(sr, sc, si);si=si+1; imshow(c5); title('plane6');
subplot(sr, sc, si);si=si+1; imshow(c6); title('plane7');
subplot(sr, sc, si);si=si+1; imshow(c7); title('plane8. MSB');

@Copyrights: Digital Image Processing Organized by Dr. Ahmad Jalal (http://portals.au.edu.pk/imc/)


3. Histogram Processing
 Histogram of a digital image with gray levels having range [0,L-1]
is a discrete function h (rk) = nk
– where “ rk” is the Kth gray level and nk is the number of pixels in the image
having gray level rk.
Definition
 A histogram is normalize by dividing each of its values by the total number of
pixels in the image, denoted by n. Note that the sum of all components of a
normalize histogram is equal to 1.

 Histogram are the basis for numerous spatial domain processing techniques.
– Used effectively for image enhancement.
– Also, useful in other image processing applications, such as image
compression and segmentation.

@Copyrights: Digital Image Processing Organized by Dr. Ahmad Jalal (http://portals.au.edu.pk/imc/)


3. Histogram Processing

Histogram h(rk )  nk
rk is the k th intensity value
nk is the number of pixels in the image with intensity rk

nk
Normalized histogram p( rk ) 
MN
nk : the number of pixels in the image of
size M  N with intensity rk

@Copyrights: Digital Image Processing Organized by Dr. Ahmad Jalal (http://portals.au.edu.pk/imc/)


3. Histogram Processing
 4 basic gray-level characteristics (the horizontal axis of each
histogram plot corresponds to gray level values).
1) Dark image: histogram are concentrated on the low (dark) side of
the gray scale.

2) Bright image: high side of the gray scale.

@Copyrights: Digital Image Processing Organized by Dr. Ahmad Jalal (http://portals.au.edu.pk/imc/)


3. Histogram Processing
 4 basic gray-level characteristics (the horizontal axis of each
histogram plot corresponds to gray level values).
3) Low contrast: a histogram that will be narrow and will be
centered towards the middle of the gray scale.

4) High-contrast image: cover a broad range of the gray scale. Also,


the distribution of pixels is not too far from uniform. (Diagram)

@Copyrights: Digital Image Processing Organized by Dr. Ahmad Jalal (http://portals.au.edu.pk/imc/)


3. Histogram Processing
(Hands-on Practices-Hour)
1) Histogram Processing
% Read source image file
img = imread('apple.jpg'); % update ith position of frequency array with count
frequency(i) = count;
% Convert image to grayscale image % reset count
img=rgb2gray(img); count = 0;

% get the dimension of the image end


[x, y] = size(img); Original Image
n = 0 : 255;
% Create a frequency array of size 256
frequency = 1 : 256; % Display Histogram
stem(n, frequency);
count = 0;
grid on;
for i = 1 : 256 ylabel('Number of pixels with such intensity levels -->');
for j = 1 : x xlabel('Intensity Levels -->');
for k = 1 : y title('HISTOGRAM OF THE IMAGE');
% if image pixel value at location (j, k) is i-1
% then increment count
if img(j, k) == i-1
count = count + 1; log=3
end
end
end

@Copyrights: Digital Image Processing Organized by Dr. Ahmad Jalal (http://portals.au.edu.pk/imc/)


3. Histogram Processing

1) Histogram Equalization:
– We assume that r has been normalized to the interval [0 ,1] with
r=0 representing black and r=1 representing white.

– We focus attention on transformations of the form;


S = T (r) 0 <r < 1
– that produce a level “s” for every pixel value “r” in the original
image.
– T (r) is single-valued of input and monotonically increasing in
the interval 0 < r < 1.

@Copyrights: Digital Image Processing Organized by Dr. Ahmad Jalal (http://portals.au.edu.pk/imc/)


3. Histogram Processing

@Copyrights: Digital Image Processing Organized by Dr. Ahmad Jalal (http://portals.au.edu.pk/imc/)


3. Histogram Processing

2) Histogram Matching (Specification):


– Histogram equalization automatically determines a
transformation function that seeks to produce an output image
that has a uniform histogram.

– The method used to generate a processed image that has a


specified histogram is called histogram matching or histogram
specification.

@Copyrights: Digital Image Processing Organized by Dr. Ahmad Jalal (http://portals.au.edu.pk/imc/)


3. Histogram Processing

2) Histogram Matching:
2.1 Histogram Statistics for Image Enhancement:-
-Statistical parameters obtainable directly from the histogram.

-We may view p (ri) as an estimate of the probability of


occurrence of gray level ri.
-where “m” is the mean value of r.

-We are interested primarily in the mean, which is a measure of


averaging gray level in an image and the variance which is a
measure of average contrast.

-Gross adjustments of overall intensity and contrast.


@Copyrights: Digital Image Processing Organized by Dr. Ahmad Jalal (http://portals.au.edu.pk/imc/)
3. Histogram Processing
2) Histogram Matching:
2.1 Histogram Statistics for Image
Enhancement:-
 2 uses of the mean and variance for
enhancement process as; (a) (b)
Original image Global mean image

(1) First, the global mean and variance are


measured over an entire image useful for
gross adjustments of overall intensity and
contrast.
(2) Second, to measure the local enhancement,
where the local mean and variance are used;
- for making changes that depends on image
characteristics in a predefined region about each
pixel in the image.
Global variance image

@Copyrights: Digital Image Processing Organized by Dr. Ahmad Jalal (http://portals.au.edu.pk/imc/)


3. Histogram Processing

3) Local Enhancement (Threshold, Single threshold, Multiple


threshold) :
– Local enhancement based on rectangular neighborhood and
move the center of this area from pixel to pixel.
– This technique is further categories into 2 main types.

(1) Fast-Pixel Searching :


– The center of the neighborhood region is moved to an adjacent
pixel location and the procedure is repeated.
– e.g., ???? [Class Assignment]

Step-by-Step illustration of the 4-neighbor searching algorithm


@Copyrights: Digital Image Processing Organized by Dr. Ahmad Jalal (http://portals.au.edu.pk/imc/)
3. Histogram Processing

3) Local Enhancement (Threshold, Single threshold, Multiple


threshold) :
(2) Full-Pixel Searching :
– Neighborhood changes during a pixel-to-pixel translation of the
region.
– e.g., ???? [Class Assignment]

Pixel-by-pixel searching algorithm Pixel-based gaming console

@Copyrights: Digital Image Processing Organized by Dr. Ahmad Jalal (http://portals.au.edu.pk/imc/)


3. Histogram Processing

3) Local Enhancement:
Advantages:
– repeatedly computing the histogram over all pixels in the
neighborhood region each time the region is moved one pixel
location.
– Improve efficiency of an image.

@Copyrights: Digital Image Processing Organized by Dr. Ahmad Jalal (http://portals.au.edu.pk/imc/)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy