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

Post on 31-Dec-2020

1 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Histogram processing

A histogram is a bar graph that shows 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.

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.

Image histogram

Grey values

Freq

ue

ncy

H(r=241) = 1

H(r=199) = 631

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

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.

Image Histogram

Image histogram

Reduce dynamic range

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)

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).

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 (𝑟𝑘).

Example of a Histogram

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

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.

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)

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);

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

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);

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)]));

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.

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).

Histogram Specification

• Define a uniform random variable

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

• That also satisfies the relation

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

• Eliminating w, we obtain

𝐹𝑣(𝑣) = 𝐹𝑢(𝑢)

𝑣 = 𝐹𝑣−1 𝐹𝑢(𝑢)

Histogram spec. for color retinal image

Red band specification

255xCDF(150)=240.9898

240.9898

234.1675

Red band specification

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.

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)).

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);

Histogram Modification Transfer Functions

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);

Histogram hyperbolization

top related