CSE 4227 · Chapter 3 · Deck 04

Intensity Transformation, from zero

Every slide you need, in plain words, with each graph drawn properly and past-paper questions solved the way you write them in the answer script. Orange Came in past papers marks topics already asked.

★ Must study on this page

Start here: what this chapter is about

slides before 4

An image is a grid of numbers. Each number is one pixel's brightness. 0 is black. The biggest number is white.

Each pixel is stored in k bits. That gives L = 2k gray levels, numbered 0 to L−1.

bits kL = 2krangewhere you meet it
120–1binary image (black/white)
380–7most exam grids
5320–31slide 13 exercise
82560–255normal photos
1010240–1023Fall 25 quiz

This whole chapter does one thing: take every pixel, put its number through a rule, and write down the new number. Old number = r, new number = s, rule = T. So s = T(r). The same rule is used for every pixel.

How to read a transformation graph

Every graph in this chapter has the old value r on the x-axis and the new value s on the y-axis. Find your pixel on the x-axis, go up to the line, then read the new value on the y-axis.

02550255r (input)s (output)above diagonal: brighterbelow: darkerdiagonal: s = r, no change
Above the dashed diagonal, output is bigger than input, so the picture gets brighter. Below it, darker.
Fall 25 Quiz 2(b)3 marks

How many shades of gray are possible in a 10-bit grayscale image? Show the numeric range. Write the expression for intensity resolution.

Intensity resolution = number of gray levels a pixel can take. With k bits per pixel:

L = 2k

Here k = 10, so L = 210 = 1024 shades.

Range: 0 to L − 1 = 0 to 1023 (0 = black, 1023 = white).

Answer1024 gray levels, from 0 to 1023. General expression: L = 2k, range [0, 2k − 1].

Image enhancement and the 3 kinds of operation

slides 4–6On study list

Slide 4. Image enhancement means processing an image so the result is more suitable than the original for a specific application. The slide stresses problem oriented: the best result for an X-ray is not the best result for a satellite photo.

Slide 5. Three kinds of operation. Ask yourself: to make one new pixel, which old pixels do I look at?

Pointinput pixels usedLocalinput pixels usedGlobalinput pixels used
Dark cells = input pixels the rule looks at. Right square = the one output pixel.

Slide 6. Intensity transformation functions remap pixel values to new intensities. General form s = T(r). Used for image enhancement and preprocessing.

The family of transformations

slides 7–9On study list

Slide 7. Intensity transformation functions fall into 2 approaches. Learn this list as it is; it answers "classify the intensity transformations".

  1. Basic intensity transformations
    • Linear: negative, identity
    • Logarithmic: log, inverse log
    • Power-law: nth power, nth root
  2. Piecewise linear transformations
    • Contrast stretching, thresholding
    • Gray-level slicing
    • Bit-plane slicing
0L/4L/23L/4L−10L/2L−1r (input)s (output)negativelognth rootnth powerinverse logidentity
Slide 7 graph. Log and nth root lie above the diagonal (brighten). nth power and inverse log lie below (darken). Negative runs downhill.

Slide 8. Identity: s = r. Output = input, so the image does not change. It is on the graph only for completeness.

Slide 9. Intensity scaling: s = a·r. Every pixel is multiplied by a. With a > 1 the face image becomes brighter.

Negative transformation

slides 10–13Came in past papers
In plain wordsFlip the brightness, like a film negative. Black becomes white, white becomes black, and middle gray stays near the middle.
0100L−10155L−1r (input)s (output)s = (L−1) − r(0, L−1)r=100 → s=155
Straight line going down. Black input (0) gives white output (L−1).
s = (L − 1) − r

Why use it (slide 11): when an image has big dark areas, small white or gray details inside them are hard to see (X-ray, mammogram). After the negative they become dark on a light background, which the eye reads more easily.

Slide 12 · Example 1worked

The matrix gives the pixel values of an 8-bit image r. Apply the negative transform and find the resulting pixel values.

Given: 8-bit image, so L = 28 = 256.

Formula: s = (L − 1) − r = 255 − r. Apply it to every pixel.

r255 − rs
85255 − 85170
88255 − 88167
89255 − 89166
90255 − 90165
95255 − 95160
98255 − 98157
99255 − 99156
100255 − 100155
102255 − 102153
105255 − 105150
110255 − 110145
115255 − 115140
135255 − 135120
140255 − 140115
145255 − 145110
1001109095
98140145135
89908885
10210599115
input image r
155145165160
157115110120
166165167170
153150156140
negative image s
Slide 13 · Exercisesolved

The matrix gives the pixel values of a 5-bit image r. Apply the negative transform.

Given: 5-bit image, so L = 25 = 32 and L − 1 = 31.

Formula: s = 31 − r.

r31 − rs
1631 − 1615
1831 − 1813
1931 − 1912
2031 − 2011
2131 − 2110
2331 − 238
2631 − 265
2731 − 274
2931 − 292
3031 − 301
3131 − 310
21262930
19212030
16162631
19182723
input r (5-bit)
10521
1210111
151550
121348
negative s
F23 Q1(b), first half2 marks

Write a short note on the Negative transformation.

The negative transformation is a basic linear intensity transformation that reverses the intensity values of an image (light ↔ dark). For an image with L gray levels in the range [0, L−1]:

s = (L − 1) − r

where r is the input and s the output gray level. Its graph is a straight line from (0, L−1) down to (L−1, 0) [draw it].

Use: enhancing white or gray detail embedded in dark regions, especially when black areas dominate, e.g. medical X-ray and mammogram images.

Example (8-bit): r = 100 gives s = 255 − 100 = 155.

TrapFind L from the bits before anything else. 3-bit: s = 7 − r. 5-bit: s = 31 − r. 8-bit: s = 255 − r.

Thresholding

slides 14–15On study list
In plain wordsPick one cut value k. Every pixel brighter than k turns white, every other pixel turns black. Like a height check at a gate: taller than k goes in, everyone else stays out.
s =
1.0 (white)
if r > k
0.0 (black)
if r ≤ k
  • The output has only 2 values, so it is a binary image.
  • It darkens levels below k and brightens levels above k: the strongest possible contrast enhancement.
  • Main job: separate the foreground (object) from the background. That is segmentation.
  • Slide 15: the moon photo becomes a white moon on a black sky.
0kL−101r (input)s (output)r > k → whiter ≤ k → black
A step: flat at 0 up to k, then a jump to the top.
Mini example (slide 75 image, T = 3)worked

Given: 3-bit image, threshold T = 3. Rule: s = 1 if r > 3, otherwise s = 0.

Values 0, 1, 2, 3 become 0. Values 4, 5, 6, 7 become 1.

21210
71432
24137
13463
14134
input r
00000
10100
01001
00110
01001
thresholded s

Log transformation (and inverse log)

slides 16–21Came in past papers
In plain wordsSome images have a huge range of values. A Fourier spectrum runs from 0 to 1,500,000, but a screen shows only 0–255. Shown as it is, you see one bright dot and black everywhere else. The log curve rises fast at first and then flattens, so it spreads the small values apart and squeezes the big ones together.
s = c · log(1 + r)
  • c is a constant and r ≥ 0.
  • We add 1 because log(0) does not exist. With +1, r = 0 gives s = 0.
  • Low input values: range expanded. Dark detail becomes visible.
  • High input values: range compressed. Glare in bright regions is reduced.
  • Slide 17: compresses the range of pixel values, expands detail in dark areas, reduces glare in bright regions (astronomy, brain scan, chess piece).
0501002550181212255r (input)s (output)s = c·log(1+r)50 → 181
Inputs 0–50 (narrow strip) spread over outputs 0–181 (wide strip): dark values expanded. Inputs 100–255 squeeze into 212–255: bright values compressed.

Slide 19. Application. Log is useful when the input gray values have an extremely large range, i.e. when the dynamic range of the image far exceeds what the display can show. Example: displaying the Fourier spectrum. It is also called dynamic-range compression.

Slide 20. Fourier spectrum with values from 0 to 1.5×106. After a log transform with c = 1, the whole pattern becomes visible.

Slide 21. Inverse log does the opposite: it expands bright values and compresses dark values. Slide formula: s = (1/c)·e(r+1).

Numeric log example (8-bit)worked

Choose c so that the top input stays at the top: c = (L−1) / log(1 + (L−1)) = 255 / log10(256) = 255 / 2.4082 = 105.89.

Formula: s = 105.89 × log10(1 + r), then round.

r1 + rlog10(1+r)× cs
010.00000.00
120.301031.932
560.778282.482
10111.0414110.3110
50511.7076180.8181
1001012.0043212.2212
2002012.3032243.9244
2552562.4082255.0255

Inputs 0–50 went to 0–181 (spread out). Inputs 100–255 went to 212–255 (squeezed). Any log base gives the same s, as long as c uses the same base.

Fall 25 Quiz 16 marks

Discuss logarithmic transformations for image enhancement.

Definition. The log transformation is a basic intensity transformation given by

s = c · log(1 + r)

where r is the input gray level, s the output gray level, c a constant and r ≥ 0. The 1 is added so that log 0 is avoided.

Shape. [Draw the log curve above the diagonal, as in the graph above.] The curve is steep for small r and flat for large r.

Properties.

  1. For lower amplitudes of the input, the range is expanded: dark regions are spread out and their details become visible.
  2. For higher amplitudes of the input, the range is compressed: bright regions are squeezed and glare is reduced.

Application. It is useful when the input values have an extremely large range, i.e. the dynamic range of the image far exceeds the capability of the display. Typical example: displaying the Fourier spectrum, whose values range from 0 to 1.5×106; after the log transform with c = 1 the spectrum becomes visible. Hence it is also called dynamic-range compression.

Example. For 8-bit with c = 105.89: r = 10 → 110, r = 50 → 181, r = 100 → 212, r = 255 → 255. A 0–50 input band becomes 0–181, while 100–255 shrinks to 212–255.

Inverse log does the opposite: it expands high values and compresses dark ones.

Power-law (gamma) transformation

slides 22–31Came in past papers
In plain wordsLog has one fixed shape. Gamma has a knob, γ, so you choose how much to brighten or darken. Turn γ below 1 for a brighter picture, above 1 for a darker one.
s = c · rγ

c and γ (gamma) are positive constants. Different curves come from different γ.

  • γ < 1: brightens the image (slide wording: "concave upward").
  • γ = 1: original, linear mapping.
  • γ > 1: darkens the image (slide wording: "concave downward").

Slide 23 waterfall: γ = 0.5 expands dark regions (brighter), γ = 2.0 compresses bright regions (darker).

0L−10L−1r (input)s (output)γ = 0.1γ = 0.4γ = 2.5γ = 10γ = 1
Figure 3.6 idea: γ < 1 curves bulge up (brighter), γ > 1 curves sag down (darker), γ = 1 is the diagonal.

How to compute gamma in the exam. Scale the pixel to 0–1 first, apply the power, then scale back. Without scaling, 72.5 = 129 falls outside a 3-bit range.

s = (L − 1) · ( r / (L − 1) )γ   then round
Practice · gamma on a 3-bit imageworked

The 3×3 image below is transformed using the gamma transformation with γ = 0.5 and γ = 2.0. Find the outputs and discuss the effect of changing γ.

146
027
352
input image

Step 1, find L. The largest value is 7, so the image is 3-bit: L = 8, L − 1 = 7. Take c = 1 on the normalized values.

Step 2, formula. s = 7 × (r/7)γ, rounded to the nearest integer.

Step 3, one value in full (r = 3, γ = 0.5): 3/7 = 0.4286; 0.42860.5 = 0.6547; 7 × 0.6547 = 4.58 → 5.

Step 4, table for every gray level, γ = 0.5:

rr/7(r/7)0.5×7s
00.00000.00000.000
10.14290.37802.653
20.28570.53453.744
30.42860.65474.585
40.57140.75595.295
50.71430.84525.926
60.85710.92586.486
71.00001.00007.007

γ = 2.0:

rr/7(r/7)2.0×7s
00.00000.00000.000
10.14290.02040.140
20.28570.08160.571
30.42860.18371.291
40.57140.32652.292
50.71430.51023.574
60.85710.73475.145
71.00001.00007.007

Step 5, replace each pixel.

146
027
352
input
356
047
564
γ = 0.5
025
017
141
γ = 2.0
0123456701234567r (input)s (output)γ = 0.5γ = 2.0
Practice mapping drawn: γ = 0.5 points sit above the diagonal, γ = 2.0 below.

Step 6, effect of γ.

  • γ = 0.5 (< 1) pushes values up: the image becomes brighter. Dark levels 1–3 are spread to 3–5 (more detail in dark areas); bright levels 4–7 bunch at 5–7.
  • γ = 2.0 (> 1) pushes values down: the image becomes darker. Levels 0–1 collapse to 0 and 2–3 to 1; bright levels 5–7 are spread to 4–7 (more detail in bright areas).
  • So a smaller γ brightens and gives contrast to dark regions; a larger γ darkens and gives contrast to bright regions. γ = 1 leaves the image unchanged.

Gamma correction (slides 24–26)

Short notetheory
  • Many devices (image capture, printing, display) respond to intensity according to a power law, so they need to be corrected. A CRT monitor has an intensity-to-voltage response with exponent about 1.8 to 2.5, so images look darker than they should.
  • Gamma correction is the process used to correct this power-law response: pre-process the image with s = c·r1/2.5 so the monitor's darkening cancels out.
  • Background: human vision is nonlinear (more sensitive to small changes in dark tones than bright ones), while digital sensors are linear.
  • Different display devices have different gammas, so each needs its own correction.
  • Why needed: to display an image accurately on screen (without correction it looks bleached out or, more likely, too dark); to reproduce colours accurately; and for general-purpose contrast manipulation.

Example pictures (slides 27–31)

TrapRule to remember: dark image → γ < 1. Washed-out image → γ > 1. Always normalize by L−1 before taking the power.

What does “piecewise” mean?

Must studyslides 32On study list
In plain wordsEverything so far used one formula for all pixels. Piecewise means a different rule for different ranges of input. Think of a phone bill: the first 100 minutes cost one rate, every minute after that another rate. Each range has its own rule. Piecewise linear means each rule is a straight line, so the graph is several straight pieces joined at corners.

In the graph, pixels with r from 0 to r1 follow piece 1, pixels from r1 to r2 follow piece 2, and pixels above r2 follow piece 3. The corners (r1, s1) and (r2, s2) are what you choose. That is why these methods need more input from the user.

  • Principal advantage: some important transformations can be formulated only as a piecewise function.
  • Principal disadvantage: their specification requires more user input than the previous transformations.
  • Types: contrast stretching, gray/intensity level slicing, bit-plane slicing.
0r1r2L−10s1s2L−1r (input)s (output)piece 1piece 2 (steep)piece 3(r1, s1)(r2, s2)
Three straight pieces joined at two bend points. Each piece is the rule for its own range of r.

Contrast stretching

Must studyslides 33–47Came in past papers

Slide 33. Contrast stretching makes the bright pixels brighter and the dark pixels darker, which gives a higher-contrast image.

Slide 34. What is contrast? Contrast is the difference between the maximum and minimum pixel intensity in an image.

100100100100
100100100100
100100100100
100100100100
100 − 100 = 0 · no contrast
0102030
40608090
100120150180
200220240255
255 − 0 = 255 · high contrast
100105107100
120125120130
115117112118
130140145150
150 − 100 = 50 · low contrast
In plain wordsA low-contrast image uses only a narrow band of gray levels, for example 100 to 151 out of 0 to 255. It looks foggy. Contrast stretching pulls that narrow band out to fill the whole range, like stretching a rubber band.

Slide 35. Contrast stretching is used to expand the range of intensity levels of a low-contrast image. Different ranges of gray levels can be enhanced independently.

Inew = (I − Min) × (NewMax − NewMin) / (Max − Min) + NewMin

Read it as: how far the pixel is above the old minimum, times how much wider the new range is, plus the new starting point.

The two control points (slides 36, 46–47)

The function is controlled by two points, a = (r1, s1) and b = (r2, s2), with r1 ≤ r2 and s1 ≤ s2, so the function is always increasing (the order of gray levels never flips). Where you put them decides what the function does:

SP23 2(d) · F22 A1(b)ii · SP22 2(a) · F21 B3(b)5–6 marks, asked 5 times

Points A(r1, s1) and B(r2, s2) control the piecewise linear transformation. Illustrate the relation between (r1, s1) and (r2, s2) for (i) linear identity (ii) thresholding (iii) contrast stretching.

The shape of the piecewise linear function s = T(r) is decided by the two points (r1, s1) and (r2, s2), with r1 ≤ r2 and s1 ≤ s2 so the function stays increasing.

(i) Linear identity: r1 = s1 and r2 = s2. Both points lie on the diagonal, so the line is s = r and the gray levels do not change.

(ii) Thresholding: r1 = r2, s1 = 0, s2 = L−1. The line jumps vertically at r1, so every pixel below r1 becomes 0 and every pixel above becomes L−1: a binary image.

(iii) Contrast stretching: r1 < r2 and s1 < s2. The middle piece between r1 and r2 is steeper than 45°, so those gray levels are spread over a wider output range and contrast increases. Special case, min-max stretching: (r1, s1) = (rmin, 0), (r2, s2) = (rmax, L−1).

0r1r2L−10s1s2L−1r (input)s (output)(r1,s1)(r2,s2)
(i) Identity: r1 = s1, r2 = s2
0r1 = r2L−10L−1r (input)s (output)(r1, 0)(r2, L−1)
(ii) Thresholding: r1 = r2, s1 = 0, s2 = L−1
0r1r2L−10s1s2L−1r (input)s (output)(r1,s1)(r2,s2)
(iii) Contrast stretching: r1 < r2, s1 < s2
F23 Q3(d) part 1 = SP24 Q3(e) part 15 marks

A 4×4 segment of an 8-bit image has range [100–151]. Find the output after contrast stretching to [0–255] using s = T(r), and express s = T(r).

100105107100
120125120130
115117112118
130140145151
input image

Given: Min = 100, Max = 151, NewMin = 0, NewMax = 255.

Formula: s = (r − Min) × (NewMax − NewMin)/(Max − Min) + NewMin

(NewMax − NewMin)/(Max − Min) = (255 − 0)/(151 − 100) = 255/51 = 5

s = T(r) = 5 (r − 100)

Apply to every gray level:

rworkings
100(255 − 0)/(151 − 100) × (100 − 100) + 0 = 5 × 00
105(255 − 0)/(151 − 100) × (105 − 100) + 0 = 5 × 525
107(255 − 0)/(151 − 100) × (107 − 100) + 0 = 5 × 735
112(255 − 0)/(151 − 100) × (112 − 100) + 0 = 5 × 1260
115(255 − 0)/(151 − 100) × (115 − 100) + 0 = 5 × 1575
117(255 − 0)/(151 − 100) × (117 − 100) + 0 = 5 × 1785
118(255 − 0)/(151 − 100) × (118 − 100) + 0 = 5 × 1890
120(255 − 0)/(151 − 100) × (120 − 100) + 0 = 5 × 20100
125(255 − 0)/(151 − 100) × (125 − 100) + 0 = 5 × 25125
130(255 − 0)/(151 − 100) × (130 − 100) + 0 = 5 × 30150
140(255 − 0)/(151 − 100) × (140 − 100) + 0 = 5 × 40200
145(255 − 0)/(151 − 100) × (145 − 100) + 0 = 5 × 45225
151(255 − 0)/(151 − 100) × (151 − 100) + 0 = 5 × 51255

Output image:

100105107100
120125120130
115117112118
130140145151
input r
025350
100125100150
75856090
150200225255
stretched s
01001512550125255r (input)s (output)s = 5(r − 100)(100, 0)(151, 255)125 → 125
Min-max stretch: the band 100–151 is spread across the whole 0–255.

Check: the old contrast was 151 − 100 = 51; the new contrast is 255 − 0 = 255. Midpoint m = 125 (slide 40).

F23 Q3(d) part 25 marks

Apply the contrast-stretching graph with a = 90, b = 180, m = 100 to the stretched image: r > 180 → 255; r < 90 → 0; between them, r < 100 moves close to 0 and r > 100 moves close to 255. Show the final image.

090m1802550255r (input)s (output)a = 90b = 180steep at m = 100r > 180 → 255
Slide 42 S-curve: below 90 → 0, above 180 → 255, between them values move away from m.
s =
255
if r > 180
close to 0 (darker)
if 90 ≤ r < 100
close to 255 (brighter)
if 100 < r ≤ 180
0
if r < 90

Apply to each stretched value (taking the curve at its limit: the dark side goes to 0 and the bright side goes to 255):

stretched rrules
0< 900
25< 900
35< 900
60< 900
75< 900
85< 900
9090–100, toward 00
100≥ 100, toward 255255
125≥ 100, toward 255255
150≥ 100, toward 255255
200> 180255
225> 180255
255> 180255

r = 100 sits exactly at m. I place it on the bright side; write your assumption in the script.

025350
100125100150
75856090
150200225255
stretched r
0000
255255255255
0000
255255255255
final output

Bright pixels became brighter and dark pixels darker, so the result has higher contrast (here, the limit is a binary image).

SP24 Q3(e) part 24 marks

Apply to the stretched image: r > 180 → 255; r < 90 → 0; 90 ≤ r ≤ 180 → negative transformation. Show the final image.

s =
255
if r > 180
255 − r
if 90 ≤ r ≤ 180
0
if r < 90
090180255075165255r (input)s (output)255 − r(90,165)(180,75)
SP24 rule: three pieces. 0 below 90, negative between 90 and 180, 255 above 180.
stretched rrules
0< 90 → 00
25< 90 → 00
35< 90 → 00
60< 90 → 00
75< 90 → 00
85< 90 → 00
90255 − 90165
100255 − 100155
125255 − 125130
150255 − 150105
200> 180 → 255255
225> 180 → 255255
255> 180 → 255255
025350
100125100150
75856090
150200225255
stretched r
0000
155130155105
000165
105255255255
final output

Slide 41: thresholding as a special case

Suppose k = 150. If r > 150 then s = 1; if r < 150 then s = 0. Pixels below 150 become 0 and pixels above become 1. This is thresholding, and it gives a binary image.

Figure 3.10 (slides 43–47)

Gray-level (intensity-level) slicing

Must studyslides 48–53Came in past papers
In plain wordsSometimes you care about one band of gray values only: bones in an X-ray at 120–200, blood vessels, a tumor. Slicing makes that band light up. Pixels inside [A, B] become bright. For the pixels outside, you choose: drop them to black, or leave them as they were.

Slide 48. Highlights a specific range of gray levels in an image. Similar to thresholding. Other levels can be suppressed or maintained. Useful when different features of an image are contained in different gray levels.

Slide 49. Two basic approaches:

0ABL−10L−1r (input)s (output)
Approach 1, without background: [A, B] → L−1, everything else → a low level (0).
0ABL−10L−1r (input)s (output)
Approach 2, with background: [A, B] → L−1, everything else unchanged (s = r).

The shaded strip is the chosen band [A, B]. In approach 2 the graph is the diagonal everywhere except inside the band, where it is lifted to the top.

Slides 50–52. MATLAB cameraman: pixels between 100 and 200 become 255 (white). Approach 1: everything else becomes 0 (black). Approach 2: everything else stays the same.

Slide 53. Aortic angiogram: slicing highlights the major blood vessels and shows the flow of the contrast medium, to detect blockages.

Fall 25 Quiz 2(a)11 marks

A medical X-ray image (8-bit) needs its bone structures in the range [120, 200] enhanced. Apply gray-level slicing with both approaches. (i) Write the transformation functions [4] (ii) Show the mapping for pixel values 100, 150 and 220 [4] (iii) Sketch the transformation curves [3].

Given: 8-bit, so L − 1 = 255. Band of interest A = 120, B = 200. Highlight level = 255.

(i) Transformation functions

Approach 1, without background (other levels suppressed):

s =
255
if 120 ≤ r ≤ 200
0
otherwise

Approach 2, with background (other levels preserved):

s =
255
if 120 ≤ r ≤ 200
r
otherwise

(ii) Mapping

rinside [120, 200]?Approach 1 sApproach 2 s
100no0100
150yes255255
220no0220

r = 100 is below the band: approach 1 gives 0, approach 2 keeps 100. r = 150 is inside: both give 255. r = 220 is above: approach 1 gives 0, approach 2 keeps 220.

(iii) Curves

01202002550255r (input)s (output)
Approach 1: 0, jump to 255 on [120, 200], back to 0.
01202002550255r (input)s (output)
Approach 2: s = r, lifted to 255 on [120, 200].

Result: approach 1 shows only the bones, white on black. Approach 2 shows the bones in white with the rest of the X-ray still visible.

F23 Q1(b), second half2 marks

Write a short note on intensity-level slicing.

Intensity-level (gray-level) slicing highlights a specific range [A, B] of gray levels in an image. It is similar to thresholding, and it is useful when different features of an image lie in different gray levels (e.g. blood vessels in an angiogram).

Two basic approaches: (1) without background: highlight [A, B] and reduce all other levels to a low constant level; (2) with background: highlight [A, B] and preserve all other levels. [Draw both small graphs.]

SP23 1(b)iii · F22 A1(b)i, tumor case3 marks

For tumor detection from medical scans, which transformation function highlights specific ranges of pixel values?

Gray-level (intensity-level) slicing. The tumor tissue occupies a particular band of gray values [A, B]. Slicing maps that band to a high value (L−1), so the tumor stands out.

It can be applied in two ways: without background (all other levels → 0, only the tumor region is visible) or with background (other levels unchanged, so the tumor is seen in its anatomical context).

s =
L − 1
if A ≤ r ≤ B
0 (or r)
otherwise

Bit-plane slicing

Must studyslides 54–74Came in past papers
In plain wordsEvery pixel is stored as bits: 167 is 10100111. Take bit 8 from every pixel and you get one black-and-white image, called bit plane 8. Take bit 7 from every pixel and you get plane 7, and so on. An 8-bit image is eight 1-bit images stacked on top of each other.

Slide 54. Bit-plane slicing separates an image into its individual bit layers, so you can see each bit's contribution to the overall image. It is widely used in image compression, data hiding and feature extraction.

Slide 55. 0 = 00000000 and 255 = 11111111. Similarly 167 = 10100111 and 144 = 10010000. The left-most bit is the most significant bit (MSB); the right-most is the least significant bit (LSB).

Slide 59. An 8-bit image is composed of eight 1-bit planes. Plane 1 holds the LSB of every pixel; plane 8 holds the MSB of every pixel.

bit plane 1 (LSB, ×1)bit plane 2 (×2)bit plane 3 (×4)bit plane 4 (×8)bit plane 5 (×16)bit plane 6 (×32)bit plane 7 (×64)bit plane 8 (MSB, ×128)one 8-bit image
An 8-bit image is eight 1-bit images stacked like pages.

Slide 56. Binary to decimal. Pixel value = 128 + 16 + 8 + 2 + 1 = 155.

position8th7th6th5th4th3rd2nd1st
value1286432168421
binary 15510011011
decimal12800168021

A change in the MSB changes the value a lot (by 128). A change in the LSB hardly changes it (by 1).

Slide 57. Higher-order bits contain most of the significant visual information. Lower-order bits contain subtle details and look like noise. Separating the planes shows the relative importance of each bit.

Slide 58. Why bit-plane slicing. Using only the MSB reduces a gray image to a binary image. The three main goals:

  1. Converting a gray-level image to a binary image.
  2. Representing an image with fewer bits, making it smaller: compression.
  3. Enhancing the image by focusing on chosen planes.
Slides 60–61 · 3-bit exampleworked

Step 1. Write each pixel of the 3-bit image in binary.

67667
00012
11123
45542
66677
3-bit image
110111110110111
000000000001010
001001001010011
100101101100010
110110110111111
binary

Step 2. Collect the 1st bit of every pixel (MSB plane), the 2nd bit (centre plane), and the 3rd bit (LSB plane).

11111
00000
00000
11110
11111
MSB plane (×4)
11111
00001
00011
00001
11111
centre plane (×2)
01001
00010
11101
01100
00011
LSB plane (×1)

Check one pixel: 6 = 110 gives MSB 1, centre 1, LSB 0.

SP25 Q2(b)i · SP24 Q2(b)i2–3 marks

A 7×7 image segment has 3 bits per pixel. The binary images of bit planes 2, 1 and 0 are given. Construct the original image.

1111111
1110111
1100011
1000001
1100011
0000000
1111111
bit plane 2 (MSB)
1111111
1111111
1000001
0000000
0000000
1111111
1111111
bit plane 1
1111111
1110111
1100011
1110111
1100011
1110111
1111111
bit plane 0 (LSB)

Rule: in a 3-bit image the planes are 2, 1, 0 with weights 22 = 4, 21 = 2, 20 = 1. So

f(x,y) = 4·b2(x,y) + 2·b1(x,y) + 1·b0(x,y)

Every bit pattern that occurs:

b2 b1 b0workingvalue
1 1 14·1 + 2·1 + 1·17
1 0 14·1 + 2·0 + 1·15
0 1 14·0 + 2·1 + 1·13
0 1 04·0 + 2·1 + 1·02
0 0 14·0 + 2·0 + 1·11
0 0 04·0 + 2·0 + 1·00

Example: row 2, column 1 has bits 1, 0, 1, so 4 + 0 + 1 = 5.

7777777
7772777
7500057
5110115
5500055
3332333
7777777
reconstructed original image

Rebuilding an image from chosen planes (slides 63–67)

The nth bit of a pixel is worth 2n−1. To rebuild from some planes, keep only those bits, multiply each by its weight, and add.

Slides 63–67worked

Given: A = [167 133 111; 144 140 135; 159 154 148] and its bit format:

101001111000010101101111
100100001000110010000111
100111111001101010010100
A in binary

8th plane only. For 10100111, multiply only the 8th bit by 27 = 128: (1×128) + (0×0) + (1×0) + (0×0) + (0×0) + (1×0) + (1×0) + (1×0) = 128. 111 = 01101111 has 8th bit 0, so it gives 0.

Bitwise AND view (slides 64–65): pixel AND 10000000 (128) keeps the 8th bit only; pixel AND 01000000 (64) keeps the 7th bit only.

1281280
128128128
128128128
8th plane image
0064
000
000
7th plane image
12812864
128128128
128128128
8th + 7th planes

8th + 7th combined (slide 66): for 10100111, (1×128) + (0×64) = 128. For 01101111, (0×128) + (1×64) = 64.

Plane 1 (LSB) and plane 8 (MSB) as 0/1 images (slides 71–72):

111
001
100
plane 1 (LSB)
110
111
111
plane 8 (MSB)
Slide 74 · Exercisesolved

Using the same A, reconstruct the image using only (a) the 5th and 4th bit planes (b) the 7th and 6th bit planes.

(a) weights 24 = 16 and 23 = 8. Example 01101111 (111): 5th bit 0, 4th bit 1, so 0 + 8 = 8. Example 10011111 (159): 16 + 8 = 24.

(b) weights 26 = 64 and 25 = 32. Example 01101111: 64 + 32 = 96. Example 10100111 (167): 0 + 32 = 32.

008
1680
242416
(a) 5th + 4th
32096
000
000
(b) 7th + 6th

(a) is dark and noisy-looking because the low planes hold little of the picture; (b) keeps more structure.

Slides 62, 68–73. Pictures (Lena, coins). Planes 1–4 look like noise; planes 5–8 show the picture. Rebuilding from planes 7+8, or 5+6+7+8, already looks close to the original.

Slide 75 classwork, solved in full

slides 75Came in past papers
Slide 75 · Class workall parts

Apply these enhancement techniques to the 3-bit image I: digital negative; bit planes; thresholding with T = 3; intensity slicing with both approaches, a = 3, b = 5, raising the level to 5. Show the enhanced images.

21210
71432
24137
13463
14134
I (3-bit)

Given: 3 bits per pixel, so L = 8 and L − 1 = 7.

(1) Digital negative. s = (L − 1) − r = 7 − r. 0→7, 1→6, 2→5, 3→4, 4→3, 6→1, 7→0.

56567
06345
53640
64314
63643
negative

(2) Bit planes. Binary: 0 = 000, 1 = 001, 2 = 010, 3 = 011, 4 = 100, 6 = 110, 7 = 111.

00000
10100
01001
00110
01001
plane 2 (MSB, ×4)
10100
10011
10011
01011
00010
plane 1 (×2)
01010
11010
00111
11001
10110
plane 0 (LSB, ×1)

Check: 4·b2 + 2·b1 + b0 rebuilds I (e.g. 6 → 1, 1, 0 → 4 + 2 = 6).

(3) Thresholding, T = 3.

s =
1
if r > 3
0
if r ≤ 3
00000
10100
01001
00110
01001
thresholded

Note: this equals the MSB plane, because r > 3 exactly when the first bit is 1.

(4) Intensity slicing, [a, b] = [3, 5], highlight level 5.

Approach 1: s =
5
if 3 ≤ r ≤ 5
0
otherwise
Approach 2: s =
5
if 3 ≤ r ≤ 5
r
otherwise
00000
00550
05050
05505
05055
without background
21210
71552
25157
15565
15155
with background
01234567057r (input)s (output)
Approach 1
01234567057r (input)s (output)
Approach 2

Case studies: which transformation for which problem

Must studyslides mixedOn study list
The story says…UseWhy
image too dark, details hidden in shadowgamma with γ < 1, or logpushes low values up
washed out, too brightgamma with γ > 1pushes values down
dull, foggy, faded, low contrastcontrast stretchingspreads the narrow range over 0 to L−1
separate object from background, binary neededthresholdingtwo output values
highlight one gray range (bone, tumor, vessel)gray-level slicinglights up [A, B] only
huge value range (Fourier spectrum)logdynamic-range compression
white detail inside large dark areas (X-ray)negativedark ↔ light
compression, data hiding, binary from MSBbit-plane slicingkeeps only chosen bits
SP25 Q3(a)i4 marks

A scanned document suffers from uneven illumination, faded ink and background noise. Describe two enhancement techniques suitable for this case.

1. Contrast stretching. Faded ink and paper occupy a narrow band of gray levels, so the text has low contrast. Stretching that band to the full [0, L−1] with s = (r − rmin)(L−1)/(rmax − rmin) makes the ink darker and the paper brighter, which improves readability.

2. Power-law (gamma) transformation with γ > 1. Faded strokes are light gray. A γ greater than 1 pushes light values down, so faint strokes become darker and clearer against the background.

(Thresholding then turns the enhanced page into black text on white, ready for OCR. For the background noise, a median filter from the smoothing chapter is the usual partner.)

Traps and one-minute sheet

slides all
methodformulaone-line meaning
identitys = rno change
scalings = a·ra > 1 brighter
negatives = (L−1) − rdark ↔ light
thresholds = 1 if r > k else 0binary, object vs background
logs = c·log(1+r)expand dark, compress bright
inverse logs = (1/c)·e(r+1)expand bright, compress dark
gammas = c·rγγ<1 brighter, γ>1 darker
stretch(I−Min)(NewMax−NewMin)/(Max−Min) + NewMinfill whole range
slicing[A,B] → L−1; else 0 or rlight up one band
bit planeΣ 2n−1·bitnimage = stack of bits