different kinds of items populationstaff.cs.psu.ac.th/sathit/dip/histogramprocessing.pdf · 2020....

31
Histogram processing A histogram is a bar graph that shows the number of occurrences of different kinds of items in a population.

Upload: others

Post on 31-Dec-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: different kinds of items populationstaff.cs.psu.ac.th/sathit/DIP/HistogramProcessing.pdf · 2020. 1. 31. · the number of occurrences of different kinds of items in a population

Histogram processing

A histogram is a bar graph that shows the number of occurrences of different

kinds of items in a population.

Page 2: different kinds of items populationstaff.cs.psu.ac.th/sathit/DIP/HistogramProcessing.pdf · 2020. 1. 31. · the number of occurrences of different kinds of items in a population

An Image Histogram

The picture shows the number of times each letter of the alphabet occurs in Lincoln’s Gettysburg Address.• The most frequently occurring letter is e and the

letters j, x, and z don’t occur at all; the letter q occurs only once.

Page 3: different kinds of items populationstaff.cs.psu.ac.th/sathit/DIP/HistogramProcessing.pdf · 2020. 1. 31. · the number of occurrences of different kinds of items in a population

The Image Histograms

A histogram for an image is a statistical summary of the set of pixels in the image.

• For a monochrome image,

– each pixel is represented by one number and the histogram is based on these numbers.

• In the case of a color image,

– we consider each color component separately, and so there is one histogram for the red values of the image, one for green, and one for blue.

Page 4: different kinds of items populationstaff.cs.psu.ac.th/sathit/DIP/HistogramProcessing.pdf · 2020. 1. 31. · the number of occurrences of different kinds of items in a population

Image histogram

Grey values

Freq

ue

ncy

H(r=241) = 1

H(r=199) = 631

Page 5: different kinds of items populationstaff.cs.psu.ac.th/sathit/DIP/HistogramProcessing.pdf · 2020. 1. 31. · the number of occurrences of different kinds of items in a population

Histogram Processing

• Process uses to transform the intensity values by using image histogram.

• Histogram processing is basic step on image processing to apply for:

–enhancement,

–compression,

– segmentation, and

–description

Page 6: different kinds of items populationstaff.cs.psu.ac.th/sathit/DIP/HistogramProcessing.pdf · 2020. 1. 31. · the number of occurrences of different kinds of items in a population

Intensity value distributions

1. Dark picture: Intensity values distribute in narrow band with the small values.

2. Too bright picture: Intensity values distribute in narrow band at the big values.

3. Low contrast: Intensity values distribute in narrow band.

4. High contrast: Intensity values distribute with the full range.

Page 7: different kinds of items populationstaff.cs.psu.ac.th/sathit/DIP/HistogramProcessing.pdf · 2020. 1. 31. · the number of occurrences of different kinds of items in a population

Image Histogram

Page 8: different kinds of items populationstaff.cs.psu.ac.th/sathit/DIP/HistogramProcessing.pdf · 2020. 1. 31. · the number of occurrences of different kinds of items in a population

Image histogram

Page 9: different kinds of items populationstaff.cs.psu.ac.th/sathit/DIP/HistogramProcessing.pdf · 2020. 1. 31. · the number of occurrences of different kinds of items in a population

Reduce dynamic range

Page 10: different kinds of items populationstaff.cs.psu.ac.th/sathit/DIP/HistogramProcessing.pdf · 2020. 1. 31. · the number of occurrences of different kinds of items in a population

DEFINITION AND EXAMPLE

• The histogram of a digital image with L total possible intensity levels in the range [0, G] is defined as the discrete function

h(x) = n

where x is the intensity values, x[0,G]

n represents the numbers of the intensity x occurred.

• An image, f, with the size, MxN. Each individual histogram entry can be expressed as:

– imSize = M*N;

– h = zeros(1,MaxGray);

– for i=1:imSize• h(f(i)) = h(f(i)+1) + 1; % MaxGray of 8-bit image is 256

h = imhist(f, b)p = imhist(f, b)/numel(f)

Page 11: different kinds of items populationstaff.cs.psu.ac.th/sathit/DIP/HistogramProcessing.pdf · 2020. 1. 31. · the number of occurrences of different kinds of items in a population

DEFINITION AND EXAMPLE

Each individual entry can be expressed mathematically as

h(k) = nk = card{(x, y)|f (x, y) = k}

• Here, k = 0, 1, ..., L − 1, where L is the number of gray levels of the digitized image, and

• card{・・・ } denotes the cardinality of a set,

• that is, the number of elements in that set (nk).

Page 12: different kinds of items populationstaff.cs.psu.ac.th/sathit/DIP/HistogramProcessing.pdf · 2020. 1. 31. · the number of occurrences of different kinds of items in a population

DEFINITION AND EXAMPLE

A normalized histogram can be mathematically defined as

p(𝑟𝑘) =𝑛𝑘𝑛

• where n is the total number of pixels in the image and

• p(𝑟𝑘) is the probability (percentage) of the k-thgray level (𝑟𝑘).

Page 13: different kinds of items populationstaff.cs.psu.ac.th/sathit/DIP/HistogramProcessing.pdf · 2020. 1. 31. · the number of occurrences of different kinds of items in a population

Example of a Histogram

Table shows the pixel counts for a hypothetical image containing 128×128 pixels, with eight grey levels.

Page 14: different kinds of items populationstaff.cs.psu.ac.th/sathit/DIP/HistogramProcessing.pdf · 2020. 1. 31. · the number of occurrences of different kinds of items in a population

Histogram EqualizationThe most usual transformation function is the cumulative distribution function (cdf) of the original probability mass function, given by

• 𝑠 = 𝑇 𝑟 = 0𝑟𝑝𝑟 𝑤 𝑑𝑤

where w is dummy variable of the integration.• Then pdf of s will be uniform distribution:

𝑝𝑠 𝑠 = ቊ1, 𝑓𝑜𝑟 0 ≤ 𝑠 ≤ 10, otherwise

• The net result of this intensity-level equalization process is an image with increased dynamic range, which will tend to have higher contrast.

Page 15: different kinds of items populationstaff.cs.psu.ac.th/sathit/DIP/HistogramProcessing.pdf · 2020. 1. 31. · the number of occurrences of different kinds of items in a population

Histogram Equalization

• For discrete quantities we work with summations, and the equalization transformation becomes

𝑠𝑘 = 𝑇 𝑟𝑘 = σ𝑗=0𝑘 𝑝𝑟(𝑟𝑗)

= σ𝑗=0𝑘 𝑛𝑗

𝑛, 𝑘 = 0,1,2, … , 𝐿 − 1

• Histogram equalization is implemented in the toolbox by function histeq, which has the syntax

g = histeq(f, nlev)

Page 16: different kinds of items populationstaff.cs.psu.ac.th/sathit/DIP/HistogramProcessing.pdf · 2020. 1. 31. · the number of occurrences of different kinds of items in a population

100 200 300 400 500

100

200

300

400

5000

2000

4000

6000

0 100 200

100 200 300 400 500

100

200

300

400

5000

2000

4000

6000

0 100 200

>>figure; >>subplot(2,2,1);>>image(f);>>subplot(2,2,2);>>imhist(f);>>g=histeq(f); %nlev=64>>subplot(2,2,3);>>image(g);>>subplot(2,2,4);>>imhist(g);

Page 17: different kinds of items populationstaff.cs.psu.ac.th/sathit/DIP/HistogramProcessing.pdf · 2020. 1. 31. · the number of occurrences of different kinds of items in a population

g=histeq(f,max(f(:)))

100 200 300 400 500

100

200

300

400

500

g=histeq(f,256)

100 200 300 400 500

100

200

300

400

5000

2000

4000

6000

imhist(g)0 100 200

0

2000

4000

6000

0 100 200

Page 18: different kinds of items populationstaff.cs.psu.ac.th/sathit/DIP/HistogramProcessing.pdf · 2020. 1. 31. · the number of occurrences of different kinds of items in a population

100 200 300 400 500

100

200

300

400

500

0 100 200 3000

0.5

1

1.5

r

cdf(

r)

0 100 200 3000

0.02

0.04

0.06

0.08

r

p(r

)

0 100 200 3000

50

100

150

200

250

300

r

s=

cdf(

r)*2

55

r=120

s=203=uint8(cdf(120)*255);

Page 19: different kinds of items populationstaff.cs.psu.ac.th/sathit/DIP/HistogramProcessing.pdf · 2020. 1. 31. · the number of occurrences of different kinds of items in a population

Histogram Equalization

𝑗=0

𝑘

𝑝𝑟(𝑟𝑗)

𝑝𝑟(𝑟𝑗)

rUniform

Quantization%S=cdf(r)*L

s

for i=1:Mfor j=1:N

g(i,j) = cdf(f(i,j))*255;end

end

50 100 150 200 250 300 350 400 450 500

50

100

150

200

250

300

350

400

450

500

>>g = uint8(reshape(s(f),[size(f)]));

Page 20: different kinds of items populationstaff.cs.psu.ac.th/sathit/DIP/HistogramProcessing.pdf · 2020. 1. 31. · the number of occurrences of different kinds of items in a population

Histogram Matching (Specification)• Histogram equalization achieves enhancement

by spreading the levels of the input image over a wider range of the intensity scale.

• Histogram matching is useful in some applications to specify the shape of the histogram that we wish the processed image to have.

• The method used to generate a processed image that has a specified histogram is called histogram matching or histogram specification.

Page 21: different kinds of items populationstaff.cs.psu.ac.th/sathit/DIP/HistogramProcessing.pdf · 2020. 1. 31. · the number of occurrences of different kinds of items in a population

Histogram Specification

• Consider for a moment continuous levels that are normalized to the interval [0,1], and let u and v denote the intensity levels of the input and output images.

• The input levels have pdf, Pu(u) and the output levels have the specified pdf, pv(v).

Page 22: different kinds of items populationstaff.cs.psu.ac.th/sathit/DIP/HistogramProcessing.pdf · 2020. 1. 31. · the number of occurrences of different kinds of items in a population

Histogram Specification

• Define a uniform random variable

𝑤 ≜ 0𝑢𝑝𝑢 𝑥 𝑑𝑥 = 𝐹𝑢(𝑢)

• That also satisfies the relation

𝑤 = 0𝑣𝑝𝑣 𝑦 𝑑𝑦 = 𝐹𝑣(𝑣)

• Eliminating w, we obtain

𝐹𝑣(𝑣) = 𝐹𝑢(𝑢)

𝑣 = 𝐹𝑣−1 𝐹𝑢(𝑢)

Page 23: different kinds of items populationstaff.cs.psu.ac.th/sathit/DIP/HistogramProcessing.pdf · 2020. 1. 31. · the number of occurrences of different kinds of items in a population

Histogram spec. for color retinal image

Page 24: different kinds of items populationstaff.cs.psu.ac.th/sathit/DIP/HistogramProcessing.pdf · 2020. 1. 31. · the number of occurrences of different kinds of items in a population

Red band specification

255xCDF(150)=240.9898

240.9898

234.1675

Page 25: different kinds of items populationstaff.cs.psu.ac.th/sathit/DIP/HistogramProcessing.pdf · 2020. 1. 31. · the number of occurrences of different kinds of items in a population

Red band specification

Page 26: different kinds of items populationstaff.cs.psu.ac.th/sathit/DIP/HistogramProcessing.pdf · 2020. 1. 31. · the number of occurrences of different kinds of items in a population

Histogram specification

0

1

2

3

4

5

x 104

0 50 100 150 200 250

Mars moon, its histogram, obtained using imhist (f). The image is dominated by large, dark areas, resulting in a histogram characterized by a large concentration of pixels in the dark end of the gray scale.

Page 27: different kinds of items populationstaff.cs.psu.ac.th/sathit/DIP/HistogramProcessing.pdf · 2020. 1. 31. · the number of occurrences of different kinds of items in a population

100 200 300 400 500 600

100

200

300

400

500

600

700

800

900

10000 100 200 300

0

0.5

1

1.5

2

2.5

3

3.5

4x 10

5

Histogram Equalization would be a good approach to enhance this image, so that details in the dark areas become more visible. >> g = histeq(f, 256);Shows that histogram equalization in fact did not produce a particularly goodresult in this case as seen from its histogram(in red), the blue one is cdf*max(imhist(f)).

Page 28: different kinds of items populationstaff.cs.psu.ac.th/sathit/DIP/HistogramProcessing.pdf · 2020. 1. 31. · the number of occurrences of different kinds of items in a population

0

1

2

3

4

5

x 104

0 50 100 150 200 250100 200 300 400 500 600

100

200

300

400

500

600

700

800

900

1000

0 50 100 150 200 250 3000

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0 50 100 150 200 250 3000

0.002

0.004

0.006

0.008

0.01

0.012

0.014

0.016

0.018

0.02

PDF of image f

Generate new PDF, p

>> g = histeq(f, p);

Page 29: different kinds of items populationstaff.cs.psu.ac.th/sathit/DIP/HistogramProcessing.pdf · 2020. 1. 31. · the number of occurrences of different kinds of items in a population

Histogram Modification Transfer Functions

Page 30: different kinds of items populationstaff.cs.psu.ac.th/sathit/DIP/HistogramProcessing.pdf · 2020. 1. 31. · the number of occurrences of different kinds of items in a population

0 100 200 3000

1

2

3

4

5

6

7x 10

-3

0 100 200 3000

0.2

0.4

0.6

0.8

1

Intensity

CD

F

0 100 200 30050

100

150

200

Original intesity

Modefied inte

nsity

x=0:255;gmin = 50;gmax = 200;in = find(x>gmin & x<gmax);u = zeros(1,256);u(in) = u(in)+ones(size(in));subplot(2, 2, 1),plot(u)xlabel('Intensity');ylabel('Uniform pdf');u=u/(gmax-gmin);plot(u)cdf = cumsum(u);subplot(2, 2, 2),plot(cdf)xlabel('Intensity');ylabel('CDF');g = (gmax-gmin)*cdf+gmin;subplot(2,2,3), plot(g)xlabel('Original intensity');ylabel(‘Modified intensity');newIm = f;inx = find(f>gmin & f<gmax);newIm(inx) = (gmax-gmin)*cdf(f(inx))+gmin;subplot(2,2,4),imshow(newIm);

Page 31: different kinds of items populationstaff.cs.psu.ac.th/sathit/DIP/HistogramProcessing.pdf · 2020. 1. 31. · the number of occurrences of different kinds of items in a population

Histogram hyperbolization