Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
1K views35 pages

Image Processing Numericals

numericals

Uploaded by

yogesh deo
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)
1K views35 pages

Image Processing Numericals

numericals

Uploaded by

yogesh deo
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/ 35

lOMoARcPSD|28843197

Numerical Examples

Digital Image Processing (‫)خيشلا رفك ةعماج‬

Scan to open on Studocu

Studocu is not sponsored or endorsed by any college or university


Downloaded by yogesh deo ([email protected])
lOMoARcPSD|28843197

Kafrelsheikh University
Faculty of Computers and informations
CS Department

Spring Semester 2022

Downloaded by yogesh deo ([email protected])


lOMoARcPSD|28843197

Image processing

Content

1. Image Transmission
2. Image Enhancement
2.1. Histogram Equalization
2.2. Contrast Stretching
3. Global Thresholding
3.1. Automatic
3.2. Manual (OutsuÕs Method)
4. Arithmetic Operations between Images
5. Negation and Bit-plane Slicing
6. Filters
6.1. Convolution
6.2. Correlation
7. Spatial Filters
7.1. Image Smoothing Filters
7.2. Sharpening Filters
7.3. Edge Detection Filters
8. Image Compression
8.1. Huffman Coding

2 Content

Downloaded by yogesh deo ([email protected])


lOMoARcPSD|28843197

Image processing Sec 01

Image Transmission

A common measure of transmission for digital data is the baud rate,


deÞned as the number of bits transmitted per second. Generally,
transmission is accomplished in packets consisting of a start bit, a byte
(8 bits) of information, and a stop bit. Using these facts, answer the
following:
(a) How many minutes would it take to transmit a 1024X1024 image
with 256 gray levels using a 56K baud modem?
(b) What would be that time at 750K baud, a representative speed
of a phone DSL (Digital Subscriber Line) connection?

(a)

(b)

3 Image Transmission

Downloaded by yogesh deo ([email protected])


lOMoARcPSD|28843197

Image processing Sec 01

Perform histogram equalization on the following 8*8 image, the gray


level distribution of the image is given below:

Gray Level 0 1 2 3 4 5 6 7

No. Of Pixels 790 1023 850 656 329 245 122 81

Gray level(rk) No. Of Pixels PDF(nk/N) CDF (L-1) * CDF Sk


(nk)

0 790 0.19 0.19 1.33 1

1 1023 0.25 0.44 3.08 3

2 850 0.21 0.65 4.55 5

3 626 0.65 0.81 5.67 6

4 329 0.08 0.89 6.23 6

5 245 0.06 0.95 6.65 7

6 122 0.03 0.98 6.86 7

7 81 0.02 1.0 7 7

Total = 4096 Total = 1

Gray Level 0 1 2 3 4 5 6 7

No. Of Pixels 0 790 0 1023 0 850 656+ 245+


329 122+
81

3 Contrast Enhancement

Downloaded by yogesh deo ([email protected])


lOMoARcPSD|28843197

Image processing Sec 02

Contrast stretching is used to increase the dynamic range of the gray


levels in the image. For example, in an 8-bit system the image display
can show a maximum of 256 gray levels. If the number of gray levels in
the recorded image spread over a lesser range, the images can be
enhanced by expanding the number of gray levels to a wider range.
This process is called contrast stretching. The resulting image displays
enhanced contrast between the features of interests.
For example, Fig. 1(a) shows the unstretched Landsat TM Band-5 image. The original
image is vague. Fig. 1 (b) shows the contrast-stretched image.

Apply contrast stretching on 3-bit gray level image of size 4 x 4

5 Contrast Enhancement

Downloaded by yogesh deo ([email protected])


lOMoARcPSD|28843197

Image processing Sec 02

Gray Level 0 1 2 3 4 5 6 7

No. Of Pixels 0 4 4 1 2 2 3 0

(lm a x − lmin)(m − m min)


L= + lmin
(m m a x − m min)

lmin = 0
lm a x = 7
m min = 1
mma x = 6
(7 − 0)(m − 1)
l= +0
(6 − 1)
7(m − 1)
l=
5

−7
m = 0,l = =0
5
00
m = 1,l = =0
5
07
m = 2,l = =1
5
14
m = 3,l = =3
5
21
m = 4,l = =4
5
28
m = 5,l = =6
5
35
m = 6,l = =7
5
42
m = 7,l = =7
5

Output Image:

Gray Level 0 1 2 3 4 5 6 7

No. Of Pixels 4 4 0 1 2 0 2 3

6 Contrast Enhancement

Downloaded by yogesh deo ([email protected])


lOMoARcPSD|28843197

Image processing Sec 02

In digital image processing, thresholding is the simplest method of


segmenting images. From a grayscale image, thresholding can be used
to create binary images.
Image thresholding be future sub-divided into the local and global
image thresholding algorithms.
In global thresholding, a single threshold is used globally, for the
whole image.
In local thresholding, some characteristics of some local image areas
(e.g. the local contrast) may be used to choose a different threshold for
different parts of the image.
OtsuÕs method is a global image thresholding algorithm.

The following matrix represents the pixels values of a 8-bit image. Apply
thresholding transform assuming that the threshold, m=95, Þnd the
resulting image pixel values

f (x, y) > = 95; g(x, y) = 1


f (x, y) < 95; g(x, y) = 0

7 Segmentation

Downloaded by yogesh deo ([email protected])


lOMoARcPSD|28843197

Image processing Sec 02

Automatic global thresholding algorithms usually have following steps.

1. Process the input image


2. Obtain image histogram (distribution of pixels)
3. Compute the threshold value
4. Replace image pixels into white in those regions, where
saturation is greater than and into the black in the opposite
cases.

Histogram of a 3 bit image is shown in the following table

Find optimal threshold using Otsu.

8 Segmentation

Downloaded by yogesh deo ([email protected])


lOMoARcPSD|28843197

Image processing Sec 03

9 Segmentation

Downloaded by yogesh deo ([email protected])


lOMoARcPSD|28843197

Image processing Sec 03

These are array operations which are carried out between corresponding
pixel pairs. The four arithmetic operations are denoted as:
S(x, y) = f (x, y) + g(x, y)
d(x, y) = f (x, y) − g(x, y)
p(x, y) = f (x, y) × g(x, y)
v(x, y) = f (x, y) ÷ g(x, y)

• If the result is a ßoating point number, round off its value.


• If the result is above the pixel range select the max range value
• If the result is below the pixel range, select the min range value
• If the result is inÞnity, write it as zero

Addition of noisy image for noise reduction.

0 100 10 10 100 5 10 200 15


4 0 10 + 2 0 0 = 6 0 10
8 0 5 0 10 10 8 10 15

Enhancement of difference between images


0 100 10 10 100 5 0 0 5
4 0 10 - 2 0 0 = 2 0 10
8 0 5 0 10 10 8 0 0

10 Segmentation

Downloaded by yogesh deo ([email protected])


lOMoARcPSD|28843197

Image processing Sec 03

Shading correction

0 100 10 10 100 5 0 255 50


4 0 10 X 2 0 0 = 8 0 0
8 0 5 0 10 10 0 0 50

Shading correction

0 100 10 10 100 5 0 1 2
4 0 10 2 0 0 = 2 0 0
8 0 5 0 10 10 0 0 0

11 Segmentation

Downloaded by yogesh deo ([email protected])


lOMoARcPSD|28843197

Image processing Sec 03

For a given image Þnd:

a. Digital negative of image


b. Bit plane slicing

Assuming the image to be 3-bit, we have.


23 = 8
L=8

(a) Negation

s = (L − 1) − r
l−1=8−1=7
g(n, y) = 7 − f (x, y)

Negative Image

12 Negation & Bit-plane slicing

Downloaded by yogesh deo ([email protected])


lOMoARcPSD|28843197

Image processing Sec 03

(b) Bit-plane slicing

Image Is broken into bits and then converted into LSB, MSB,..etc.
in this, we assumed it is 3-bit image Converting every pixel value in 3-bit

break it into planes:


MSB ÑÑ> left most bits
Center plane ÑÑ> central bits
LSB ÑÑ> Right most bits

MSB plane Center-bit plane LSB plane

13 Negation & Bit-plane slicing

Downloaded by yogesh deo ([email protected])


lOMoARcPSD|28843197

Image processing Sec 03

Point processing: applies a function to each pixel


Neighborhood processing: applies a function to a neighborhood of each pixel.

Neighborhood (mask) can have different shapes and sizes.


Function + Mask = Filter

Filtering is a technique for modifying or enhancing an image. For


example, you can Þlter an image to emphasize certain features or
remove other features. Image processing operations implemented with
Þltering include smoothing, sharpening, and edge enhancement.
Filtering is a neighborhood operation, in which the value of any given
pixel in the output image is determined by applying some algorithm to
the values of the pixels in the neighborhood of the corresponding input
pixel. A pixel's neighborhood is some set of pixels, deÞned by their
locations relative to that pixel.

• Linear smoothing Þltering is Þltering in which the value of an output


pixel is a linear combination of the values of the pixels in the input
pixel's neighborhood.
• Non linear smoothing Þlters is based on ordering(ranking) the pixels
contained in the image area.

14 Filters

Downloaded by yogesh deo ([email protected])


lOMoARcPSD|28843197

Image processing Sec 03

Linear Þltering of an image is accomplished through an operation called


convolution. Convolution is a neighborhood operation in which each
output pixel is the weighted sum of neighboring input pixels. The matrix
of weights is called the convolution kernel, also known as the Þlter. A
convolution kernel is a correlation kernel that has been rotated 180
degrees.

Compute the pixel(2,4) = 14 output of convolution:

suppose the image is


A = [17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9]
and the correlation kernel is
h = [8 1 6
3 5 7
4 9 2]

You would use the following steps to compute the output pixel at
position (2,4):
1. Rotate the correlation kernel 180 degrees about its center
element to create a convolution kernel.
2. Slide the center element of the convolution kernel so that it lies
on top of the (2,4) element of A.
3. Multiply each weight in the rotated convolution kernel by the pixel
of A underneath.
4. Sum the individual products from step 3.
15 Filters

Downloaded by yogesh deo ([email protected])


lOMoARcPSD|28843197

Image processing Sec 03

Hence the (2,4) output pixel is

16 Filters

Downloaded by yogesh deo ([email protected])


lOMoARcPSD|28843197

Image processing Sec 03

The operation called correlation is closely related to convolution. In correlation, the


value of an output pixel is also computed as a weighted sum of neighboring pixels.
The difference is that the matrix of weights, in this case called the correlation
kernel, is not rotated during the computation. Correlation Is used to match a
template to an image.

Compute the pixel(2,4) = 14 output of correlation:

suppose the image is


A = [17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9]
and the correlation kernel is
h = [8 1 6
3 5 7
4 9 2]

assuming h is a correlation kernel instead of a convolution kernel, using


these steps:
1. Slide the center element of the correlation kernel so that lies on
top of the (2,4) element of A.
2. Multiply each weight in the correlation kernel by the pixel of A
underneath.
3. Sum the individual products.

17 Filters

Downloaded by yogesh deo ([email protected])


lOMoARcPSD|28843197

Image processing Sec 03

The (2,4) output pixel from the correlation is

18 Filters

Downloaded by yogesh deo ([email protected])


lOMoARcPSD|28843197

Image processing Sec 03

Image smoothing Þlters, which include the Gaussian, Maximum, Mean,


Median, Minimum, Non-Local Means, Percentile, and Rank Þlters, can
be applied to reduce the amount of noise in an image. You should note
that although these Þlters can effectively reduce noise, they must be
used with care so as to not alter important information contained in the
image. You should also note that in many cases, edge detection or
enhancement should not be applied before smoothing.

Consider the image below and calculate the output of the pixel (2,2) = 6
if something is done using 3*3
neighborhood using the Þlters below:
a. Box/ mean Þlter
b. Weighted average Þlter
c. Median Þlter
d. Min Þlter
e. Max Þlter

(a) Box Filter

1
9

19 Filters

Downloaded by yogesh deo ([email protected])


lOMoARcPSD|28843197

Image processing Sec 03


1
pi xel(2,2) = [7 + 9 + 5 + 4 + 6 + 8 + 2 + 0 + 1]
9

1
16

1
pi xel(2,2) = [7 * 1 + 9 * 2 + 5 * 1 + 4 * 2 + 6 * 4 + 8 * 2 + 2 * 1 + 0 * 2 + 1 * 1] = 5
16

pi xel(2,2) = 0

pi xel(2,2) = 9

20 Filters

Downloaded by yogesh deo ([email protected])


lOMoARcPSD|28843197

Image processing Sec 04

• To highlight Þne detail in an image or to enhance detail that has been


blurred, either in error or as a natural effect of a particular method of
image acquisition
• The principal objective of sharpening is to highlight transition in
intensity.

• Blurring/smooth is done in spatial domain by pixel averaging in a


neighbors, it is a process of integration
• Sharpening is an inverse process, to Þnd the difference by the
neighborhood, done by spatial differentiation.

• It highlights gray-level discontinuities in an image (Remove blurring


from an image).
• It deemphasizes regions with slowly varying gray levels

Or

Give the same result

21 Filters

Downloaded by yogesh deo ([email protected])


lOMoARcPSD|28843197

Image processing Sec 04

+ =

+ =

22 Filters

Downloaded by yogesh deo ([email protected])


lOMoARcPSD|28843197

Image processing Sec 04

Apply laplacian Þlter on the given image on the center pixel

8 5 4

0 6 2

1 3 7

Pixel(1,1) = (8 * 0) + (5 * −1) + (4 * 0) + (0 * −1) + (6 * 4) + (2 * −1) + (1 * 0) + (3 * −1) + (7 * 0) = 14

Pi xel(1,1) = − 1[8 + 5 + 4 + 2 + 7 + 3 + 1 + 0] + (6 * 8) = 18

23 Filters

Downloaded by yogesh deo ([email protected])


lOMoARcPSD|28843197

Image processing Sec 04

Apply enhanced laplacian Þlter on the given image on the center pixel

8 5 4
0 6 2
1 3 7

pi xel(1,1) = − 1(8 + 5 + 4 + 0 + 2 + 1 + 3 + 7) + (−9 * 6) = − 30 + 54 = 24

pi xel(1,1) = − 1(8 + 5 + 4 + 0 + 2 + 1 + 3 + 7) + (5 * 6) = − 30 + 30 = 0

24 Filters

Downloaded by yogesh deo ([email protected])


lOMoARcPSD|28843197

Image processing Sec 04

Apply laplacian Þlter on the given image:

Pixel Replication

50 50 50 50 100 100 100 100

50 50 50 50 100 100 100 100


50 50 50 50 100 100 100 100
50 50 50 50 100 100 100 100
100 100 100 100 50 50 50 50

100 100 100 100 50 50 50 50

100 100 100 100 50 50 50 50

100 100 100 100 50 50 50 50

Input image

0 0 150 -150 0 0
0 0 150 -150 0 0
150 150 200 -200 -150 -150
-150 -150 -200 200 150 150
0 0 -150 150 0 0
0 0 -150 150 0 0

25 Filters

Downloaded by yogesh deo ([email protected])


lOMoARcPSD|28843197

Image processing Sec 04

The high-boost Þlter is a simple sharpening operator in signal and


image processing.

where A >= 1, a speciÞes the amount of sharpening of the image

0 -1 0 -1 -1 -1

-1 A+4 -1 Or -1 A+8 -1

0 -1 0 -1 -1 -1

Apply highboost Þlter on the image given below on the center pixel. Use
the mask with A = 1.7

1 2 3

4 5 6

7 8 9

1 2 3 -1 -1 -1

4 5 6 X -1 A+8 -1

7 8 9 -1 -1 -1

Pixel(1,1) = − 1(1 + 2 + 3 + 4 + 6 + 7 + 8 + 9) + 5(A + 8) = − 1(40) + 5(A + 8) = − 40 + 5(9.7) = − 40 + 48.5 = 8.5

26 Filters

Downloaded by yogesh deo ([email protected])


lOMoARcPSD|28843197

Image processing Sec 04

1 2 3 0 -1 0

4 5 6 X -1 A+4 -1

7 8 9 0 -1 0

Pixel(1,1) = − 1(1 + 2 + 3 + 4 + 6 + 7 + 8 + 9) + 5(A + 4) = − 1(40) + 5(A + 8) = − 40 + 5(5.7) = − 40 + 28.5 = − 11

27 Filters

Downloaded by yogesh deo ([email protected])


lOMoARcPSD|28843197

Image processing Sec 05

Edges represents the object boundaries. So edge detection is a very


important preprocessing step for any object detection or recognition
process. Simple edge detection kernels are based on approximation of
gradient images. Another advanced edge detection algorithms will
discussed in details.

28 Edge Detection

Downloaded by yogesh deo ([email protected])


lOMoARcPSD|28843197

Image processing Sec 05

Apply edge detection kernels on the pixel(1,1) in the following image

a. Prewitt operators
b. Sobel operators

(A) Prewitt operators

Ix = X

Ix = − 1(50 * 50 * 50) + 1(100 + 100 + 100) = − 150 + 300 = 150

Iy = X

Iy = − 1(50 + 50 + 100) + 1(50 + 50 + 100) = 0

I= Ix 2 + Iy 2 = 150 2 + 0 2 = 150

29 Edge Detection

Downloaded by yogesh deo ([email protected])


lOMoARcPSD|28843197

Image processing Sec 05

(B) sobel operators

Ix = X

Ix = 50(−1) + 50(−2) + 50(−1) + 100(1) + 100(2) + 100(1) = 200

Iy = X

Iy = 50(−1) + 50(−2) + 100(−1) + 50(1) + 50(2) + 100(1) = 0

I= Ix 2 + Iy 2 = 200 2 + 0 2 = 200

30 Edge Detection

Downloaded by yogesh deo ([email protected])


lOMoARcPSD|28843197

Image processing Sec 06

Image compression is minimizing the size in bytes of a graphics Þle


without degrading the quality of the image to an unacceptable level.
The reduction in Þle size allows more images to be stored in a given
amount of disk or memory space. It also reduces the time required for
images to be sent over the Internet or downloaded from Web pages.

Image compression has two prime categories - lossless and lossy


image compression. These vary based on the image Þle resizing
process. While the former ensures the image quality remains intact,
the latter removes some parts to get a smaller size.

• Lossless compression refers to a process of resizing the images into a


smaller version. This technique does not Þddle with the image quality.
• Though it is an excellent method to resize your image Þles, the
outcome may still not be too small. That is because lossless
compression does not eliminate any part of the image.
• Lossless image compression is particularly useful when compressing
text. That is because a small change in the original version can
dramatically change the text or data meaning.
• GIF (Graphic interchange Þle) is lossless compression.

• Lossy compression reduces the image size by removing some of the


image parts. It eliminates the tags that are not very essential.
• If you opt for this method, you can get a signiÞcantly smaller version
of an image with a minimal quality difference. Additionally, you can
enjoy a faster loading speed.
• Lossless image compression is particularly useful when compressing
text. That is because a small change in the original version can
dramatically change the text or data meaning.
• JPEG is lossy compression.

31 Image Compression

Downloaded by yogesh deo ([email protected])


lOMoARcPSD|28843197

Image processing Sec 06

Consider an 8-bit image of 256 X 256 pixels. after compression, the


image size is 6,554 bytes. Find the compression ratio.

UncompressedFileSize Sizeu
CompressionRatio = =
CompressedFileSize Sizec

Sizeu = 256 × 256 × 8 = 65,536bytes

65,536
compressionRatio = = 9.999 ≈ 10 (also written as 10:1)
6554

This means that the original image has 10 bytes for every 1 byte in the
compressed image.

32 Image Compression

Downloaded by yogesh deo ([email protected])


lOMoARcPSD|28843197

Image processing Sec 06

Huffman Coding

Consider 8-bit gray image show below. Use Huffman Coding technique
for eliminating coding redundancy in this image.

119 123 168 119


123 119 168 168
119 119 107 119
107 107 119 119

Gray level No. Pixels Probability


119 8 0.5 1 0.5 0.5 1
168 3 0.1875 00 0.3125 01 0.5 0
107 3 0.1875 011 0.187 00
123 2 0.125 000
Total = 16

Gray level Probability Code


119 0.5 1
168 0.1875 00
107 0.1875 011
123 0.125 010

33 Image Compression

Downloaded by yogesh deo ([email protected])


lOMoARcPSD|28843197

Image processing Sec 06

We use this code to represent the gray level values of the compressed
image:

1 010 00 1
010 1 0 0
1 1 011 1
011 011 1 1

Hence, the total number of bits required to represent the gray levels of
the compressed image is 29-bit:
Whereas the original (uncompressed) image requires 4*4*8 = 128

128
CompressionRatio = ≈ 4.4
29

34 Image Compression

Downloaded by yogesh deo ([email protected])

You might also like