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.
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 k | L = 2k | range | where you meet it |
|---|---|---|---|
| 1 | 2 | 0–1 | binary image (black/white) |
| 3 | 8 | 0–7 | most exam grids |
| 5 | 32 | 0–31 | slide 13 exercise |
| 8 | 256 | 0–255 | normal photos |
| 10 | 1024 | 0–1023 | Fall 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.
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.
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:
Here k = 10, so L = 210 = 1024 shades.
Range: 0 to L − 1 = 0 to 1023 (0 = black, 1023 = white).
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?
Slide 6. Intensity transformation functions remap pixel values to new intensities. General form s = T(r). Used for image enhancement and preprocessing.
Slide 7. Intensity transformation functions fall into 2 approaches. Learn this list as it is; it answers "classify the intensity transformations".
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.
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.
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.
| r | 255 − r | s |
|---|---|---|
| 85 | 255 − 85 | 170 |
| 88 | 255 − 88 | 167 |
| 89 | 255 − 89 | 166 |
| 90 | 255 − 90 | 165 |
| 95 | 255 − 95 | 160 |
| 98 | 255 − 98 | 157 |
| 99 | 255 − 99 | 156 |
| 100 | 255 − 100 | 155 |
| 102 | 255 − 102 | 153 |
| 105 | 255 − 105 | 150 |
| 110 | 255 − 110 | 145 |
| 115 | 255 − 115 | 140 |
| 135 | 255 − 135 | 120 |
| 140 | 255 − 140 | 115 |
| 145 | 255 − 145 | 110 |
| 100 | 110 | 90 | 95 |
| 98 | 140 | 145 | 135 |
| 89 | 90 | 88 | 85 |
| 102 | 105 | 99 | 115 |
| 155 | 145 | 165 | 160 |
| 157 | 115 | 110 | 120 |
| 166 | 165 | 167 | 170 |
| 153 | 150 | 156 | 140 |
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.
| r | 31 − r | s |
|---|---|---|
| 16 | 31 − 16 | 15 |
| 18 | 31 − 18 | 13 |
| 19 | 31 − 19 | 12 |
| 20 | 31 − 20 | 11 |
| 21 | 31 − 21 | 10 |
| 23 | 31 − 23 | 8 |
| 26 | 31 − 26 | 5 |
| 27 | 31 − 27 | 4 |
| 29 | 31 − 29 | 2 |
| 30 | 31 − 30 | 1 |
| 31 | 31 − 31 | 0 |
| 21 | 26 | 29 | 30 |
| 19 | 21 | 20 | 30 |
| 16 | 16 | 26 | 31 |
| 19 | 18 | 27 | 23 |
| 10 | 5 | 2 | 1 |
| 12 | 10 | 11 | 1 |
| 15 | 15 | 5 | 0 |
| 12 | 13 | 4 | 8 |
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]:
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.
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.
| 2 | 1 | 2 | 1 | 0 |
| 7 | 1 | 4 | 3 | 2 |
| 2 | 4 | 1 | 3 | 7 |
| 1 | 3 | 4 | 6 | 3 |
| 1 | 4 | 1 | 3 | 4 |
| 0 | 0 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 | 0 |
| 0 | 1 | 0 | 0 | 1 |
| 0 | 0 | 1 | 1 | 0 |
| 0 | 1 | 0 | 0 | 1 |
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).
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.
| r | 1 + r | log10(1+r) | × c | s |
|---|---|---|---|---|
| 0 | 1 | 0.0000 | 0.0 | 0 |
| 1 | 2 | 0.3010 | 31.9 | 32 |
| 5 | 6 | 0.7782 | 82.4 | 82 |
| 10 | 11 | 1.0414 | 110.3 | 110 |
| 50 | 51 | 1.7076 | 180.8 | 181 |
| 100 | 101 | 2.0043 | 212.2 | 212 |
| 200 | 201 | 2.3032 | 243.9 | 244 |
| 255 | 256 | 2.4082 | 255.0 | 255 |
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.
Discuss logarithmic transformations for image enhancement.
Definition. The log transformation is a basic intensity transformation given by
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.
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.
c and γ (gamma) are positive constants. Different curves come from different γ.
Slide 23 waterfall: γ = 0.5 expands dark regions (brighter), γ = 2.0 compresses bright regions (darker).
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.
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 γ.
| 1 | 4 | 6 |
| 0 | 2 | 7 |
| 3 | 5 | 2 |
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:
| r | r/7 | (r/7)0.5 | ×7 | s |
|---|---|---|---|---|
| 0 | 0.0000 | 0.0000 | 0.00 | 0 |
| 1 | 0.1429 | 0.3780 | 2.65 | 3 |
| 2 | 0.2857 | 0.5345 | 3.74 | 4 |
| 3 | 0.4286 | 0.6547 | 4.58 | 5 |
| 4 | 0.5714 | 0.7559 | 5.29 | 5 |
| 5 | 0.7143 | 0.8452 | 5.92 | 6 |
| 6 | 0.8571 | 0.9258 | 6.48 | 6 |
| 7 | 1.0000 | 1.0000 | 7.00 | 7 |
γ = 2.0:
| r | r/7 | (r/7)2.0 | ×7 | s |
|---|---|---|---|---|
| 0 | 0.0000 | 0.0000 | 0.00 | 0 |
| 1 | 0.1429 | 0.0204 | 0.14 | 0 |
| 2 | 0.2857 | 0.0816 | 0.57 | 1 |
| 3 | 0.4286 | 0.1837 | 1.29 | 1 |
| 4 | 0.5714 | 0.3265 | 2.29 | 2 |
| 5 | 0.7143 | 0.5102 | 3.57 | 4 |
| 6 | 0.8571 | 0.7347 | 5.14 | 5 |
| 7 | 1.0000 | 1.0000 | 7.00 | 7 |
Step 5, replace each pixel.
| 1 | 4 | 6 |
| 0 | 2 | 7 |
| 3 | 5 | 2 |
| 3 | 5 | 6 |
| 0 | 4 | 7 |
| 5 | 6 | 4 |
| 0 | 2 | 5 |
| 0 | 1 | 7 |
| 1 | 4 | 1 |
Step 6, effect of γ.
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.
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.
| 100 | 100 | 100 | 100 |
| 100 | 100 | 100 | 100 |
| 100 | 100 | 100 | 100 |
| 100 | 100 | 100 | 100 |
| 0 | 10 | 20 | 30 |
| 40 | 60 | 80 | 90 |
| 100 | 120 | 150 | 180 |
| 200 | 220 | 240 | 255 |
| 100 | 105 | 107 | 100 |
| 120 | 125 | 120 | 130 |
| 115 | 117 | 112 | 118 |
| 130 | 140 | 145 | 150 |
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.
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 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:
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).
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).
| 100 | 105 | 107 | 100 |
| 120 | 125 | 120 | 130 |
| 115 | 117 | 112 | 118 |
| 130 | 140 | 145 | 151 |
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
Apply to every gray level:
| r | working | s |
|---|---|---|
| 100 | (255 − 0)/(151 − 100) × (100 − 100) + 0 = 5 × 0 | 0 |
| 105 | (255 − 0)/(151 − 100) × (105 − 100) + 0 = 5 × 5 | 25 |
| 107 | (255 − 0)/(151 − 100) × (107 − 100) + 0 = 5 × 7 | 35 |
| 112 | (255 − 0)/(151 − 100) × (112 − 100) + 0 = 5 × 12 | 60 |
| 115 | (255 − 0)/(151 − 100) × (115 − 100) + 0 = 5 × 15 | 75 |
| 117 | (255 − 0)/(151 − 100) × (117 − 100) + 0 = 5 × 17 | 85 |
| 118 | (255 − 0)/(151 − 100) × (118 − 100) + 0 = 5 × 18 | 90 |
| 120 | (255 − 0)/(151 − 100) × (120 − 100) + 0 = 5 × 20 | 100 |
| 125 | (255 − 0)/(151 − 100) × (125 − 100) + 0 = 5 × 25 | 125 |
| 130 | (255 − 0)/(151 − 100) × (130 − 100) + 0 = 5 × 30 | 150 |
| 140 | (255 − 0)/(151 − 100) × (140 − 100) + 0 = 5 × 40 | 200 |
| 145 | (255 − 0)/(151 − 100) × (145 − 100) + 0 = 5 × 45 | 225 |
| 151 | (255 − 0)/(151 − 100) × (151 − 100) + 0 = 5 × 51 | 255 |
Output image:
| 100 | 105 | 107 | 100 |
| 120 | 125 | 120 | 130 |
| 115 | 117 | 112 | 118 |
| 130 | 140 | 145 | 151 |
| 0 | 25 | 35 | 0 |
| 100 | 125 | 100 | 150 |
| 75 | 85 | 60 | 90 |
| 150 | 200 | 225 | 255 |
Check: the old contrast was 151 − 100 = 51; the new contrast is 255 − 0 = 255. Midpoint m = 125 (slide 40).
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.
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 r | rule | s |
|---|---|---|
| 0 | < 90 | 0 |
| 25 | < 90 | 0 |
| 35 | < 90 | 0 |
| 60 | < 90 | 0 |
| 75 | < 90 | 0 |
| 85 | < 90 | 0 |
| 90 | 90–100, toward 0 | 0 |
| 100 | ≥ 100, toward 255 | 255 |
| 125 | ≥ 100, toward 255 | 255 |
| 150 | ≥ 100, toward 255 | 255 |
| 200 | > 180 | 255 |
| 225 | > 180 | 255 |
| 255 | > 180 | 255 |
r = 100 sits exactly at m. I place it on the bright side; write your assumption in the script.
| 0 | 25 | 35 | 0 |
| 100 | 125 | 100 | 150 |
| 75 | 85 | 60 | 90 |
| 150 | 200 | 225 | 255 |
| 0 | 0 | 0 | 0 |
| 255 | 255 | 255 | 255 |
| 0 | 0 | 0 | 0 |
| 255 | 255 | 255 | 255 |
Bright pixels became brighter and dark pixels darker, so the result has higher contrast (here, the limit is a binary image).
Apply to the stretched image: r > 180 → 255; r < 90 → 0; 90 ≤ r ≤ 180 → negative transformation. Show the final image.
| stretched r | rule | s |
|---|---|---|
| 0 | < 90 → 0 | 0 |
| 25 | < 90 → 0 | 0 |
| 35 | < 90 → 0 | 0 |
| 60 | < 90 → 0 | 0 |
| 75 | < 90 → 0 | 0 |
| 85 | < 90 → 0 | 0 |
| 90 | 255 − 90 | 165 |
| 100 | 255 − 100 | 155 |
| 125 | 255 − 125 | 130 |
| 150 | 255 − 150 | 105 |
| 200 | > 180 → 255 | 255 |
| 225 | > 180 → 255 | 255 |
| 255 | > 180 → 255 | 255 |
| 0 | 25 | 35 | 0 |
| 100 | 125 | 100 | 150 |
| 75 | 85 | 60 | 90 |
| 150 | 200 | 225 | 255 |
| 0 | 0 | 0 | 0 |
| 155 | 130 | 155 | 105 |
| 0 | 0 | 0 | 165 |
| 105 | 255 | 255 | 255 |
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.
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:
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.
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):
Approach 2, with background (other levels preserved):
(ii) Mapping
| r | inside [120, 200]? | Approach 1 s | Approach 2 s |
|---|---|---|---|
| 100 | no | 0 | 100 |
| 150 | yes | 255 | 255 |
| 220 | no | 0 | 220 |
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
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.
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.]
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).
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.
Slide 56. Binary to decimal. Pixel value = 128 + 16 + 8 + 2 + 1 = 155.
| position | 8th | 7th | 6th | 5th | 4th | 3rd | 2nd | 1st |
|---|---|---|---|---|---|---|---|---|
| value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
| binary 155 | 1 | 0 | 0 | 1 | 1 | 0 | 1 | 1 |
| decimal | 128 | 0 | 0 | 16 | 8 | 0 | 2 | 1 |
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:
Step 1. Write each pixel of the 3-bit image in binary.
| 6 | 7 | 6 | 6 | 7 |
| 0 | 0 | 0 | 1 | 2 |
| 1 | 1 | 1 | 2 | 3 |
| 4 | 5 | 5 | 4 | 2 |
| 6 | 6 | 6 | 7 | 7 |
| 110 | 111 | 110 | 110 | 111 |
| 000 | 000 | 000 | 001 | 010 |
| 001 | 001 | 001 | 010 | 011 |
| 100 | 101 | 101 | 100 | 010 |
| 110 | 110 | 110 | 111 | 111 |
Step 2. Collect the 1st bit of every pixel (MSB plane), the 2nd bit (centre plane), and the 3rd bit (LSB plane).
| 1 | 1 | 1 | 1 | 1 |
| 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 |
| 1 | 1 | 1 | 1 | 0 |
| 1 | 1 | 1 | 1 | 1 |
| 1 | 1 | 1 | 1 | 1 |
| 0 | 0 | 0 | 0 | 1 |
| 0 | 0 | 0 | 1 | 1 |
| 0 | 0 | 0 | 0 | 1 |
| 1 | 1 | 1 | 1 | 1 |
| 0 | 1 | 0 | 0 | 1 |
| 0 | 0 | 0 | 1 | 0 |
| 1 | 1 | 1 | 0 | 1 |
| 0 | 1 | 1 | 0 | 0 |
| 0 | 0 | 0 | 1 | 1 |
Check one pixel: 6 = 110 gives MSB 1, centre 1, LSB 0.
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.
| 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| 1 | 1 | 1 | 0 | 1 | 1 | 1 |
| 1 | 1 | 0 | 0 | 0 | 1 | 1 |
| 1 | 0 | 0 | 0 | 0 | 0 | 1 |
| 1 | 1 | 0 | 0 | 0 | 1 | 1 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| 1 | 0 | 0 | 0 | 0 | 0 | 1 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| 1 | 1 | 1 | 0 | 1 | 1 | 1 |
| 1 | 1 | 0 | 0 | 0 | 1 | 1 |
| 1 | 1 | 1 | 0 | 1 | 1 | 1 |
| 1 | 1 | 0 | 0 | 0 | 1 | 1 |
| 1 | 1 | 1 | 0 | 1 | 1 | 1 |
| 1 | 1 | 1 | 1 | 1 | 1 | 1 |
Rule: in a 3-bit image the planes are 2, 1, 0 with weights 22 = 4, 21 = 2, 20 = 1. So
Every bit pattern that occurs:
| b2 b1 b0 | working | value |
|---|---|---|
| 1 1 1 | 4·1 + 2·1 + 1·1 | 7 |
| 1 0 1 | 4·1 + 2·0 + 1·1 | 5 |
| 0 1 1 | 4·0 + 2·1 + 1·1 | 3 |
| 0 1 0 | 4·0 + 2·1 + 1·0 | 2 |
| 0 0 1 | 4·0 + 2·0 + 1·1 | 1 |
| 0 0 0 | 4·0 + 2·0 + 1·0 | 0 |
Example: row 2, column 1 has bits 1, 0, 1, so 4 + 0 + 1 = 5.
| 7 | 7 | 7 | 7 | 7 | 7 | 7 |
| 7 | 7 | 7 | 2 | 7 | 7 | 7 |
| 7 | 5 | 0 | 0 | 0 | 5 | 7 |
| 5 | 1 | 1 | 0 | 1 | 1 | 5 |
| 5 | 5 | 0 | 0 | 0 | 5 | 5 |
| 3 | 3 | 3 | 2 | 3 | 3 | 3 |
| 7 | 7 | 7 | 7 | 7 | 7 | 7 |
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.
Given: A = [167 133 111; 144 140 135; 159 154 148] and its bit format:
| 10100111 | 10000101 | 01101111 |
| 10010000 | 10001100 | 10000111 |
| 10011111 | 10011010 | 10010100 |
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.
| 128 | 128 | 0 |
| 128 | 128 | 128 |
| 128 | 128 | 128 |
| 0 | 0 | 64 |
| 0 | 0 | 0 |
| 0 | 0 | 0 |
| 128 | 128 | 64 |
| 128 | 128 | 128 |
| 128 | 128 | 128 |
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):
| 1 | 1 | 1 |
| 0 | 0 | 1 |
| 1 | 0 | 0 |
| 1 | 1 | 0 |
| 1 | 1 | 1 |
| 1 | 1 | 1 |
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.
| 0 | 0 | 8 |
| 16 | 8 | 0 |
| 24 | 24 | 16 |
| 32 | 0 | 96 |
| 0 | 0 | 0 |
| 0 | 0 | 0 |
(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.
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.
| 2 | 1 | 2 | 1 | 0 |
| 7 | 1 | 4 | 3 | 2 |
| 2 | 4 | 1 | 3 | 7 |
| 1 | 3 | 4 | 6 | 3 |
| 1 | 4 | 1 | 3 | 4 |
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.
| 5 | 6 | 5 | 6 | 7 |
| 0 | 6 | 3 | 4 | 5 |
| 5 | 3 | 6 | 4 | 0 |
| 6 | 4 | 3 | 1 | 4 |
| 6 | 3 | 6 | 4 | 3 |
(2) Bit planes. Binary: 0 = 000, 1 = 001, 2 = 010, 3 = 011, 4 = 100, 6 = 110, 7 = 111.
| 0 | 0 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 | 0 |
| 0 | 1 | 0 | 0 | 1 |
| 0 | 0 | 1 | 1 | 0 |
| 0 | 1 | 0 | 0 | 1 |
| 1 | 0 | 1 | 0 | 0 |
| 1 | 0 | 0 | 1 | 1 |
| 1 | 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 1 | 1 |
| 0 | 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 | 0 |
| 0 | 0 | 1 | 1 | 1 |
| 1 | 1 | 0 | 0 | 1 |
| 1 | 0 | 1 | 1 | 0 |
Check: 4·b2 + 2·b1 + b0 rebuilds I (e.g. 6 → 1, 1, 0 → 4 + 2 = 6).
(3) Thresholding, T = 3.
| 0 | 0 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 | 0 |
| 0 | 1 | 0 | 0 | 1 |
| 0 | 0 | 1 | 1 | 0 |
| 0 | 1 | 0 | 0 | 1 |
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.
| 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 5 | 5 | 0 |
| 0 | 5 | 0 | 5 | 0 |
| 0 | 5 | 5 | 0 | 5 |
| 0 | 5 | 0 | 5 | 5 |
| 2 | 1 | 2 | 1 | 0 |
| 7 | 1 | 5 | 5 | 2 |
| 2 | 5 | 1 | 5 | 7 |
| 1 | 5 | 5 | 6 | 5 |
| 1 | 5 | 1 | 5 | 5 |
| The story says… | Use | Why |
|---|---|---|
| image too dark, details hidden in shadow | gamma with γ < 1, or log | pushes low values up |
| washed out, too bright | gamma with γ > 1 | pushes values down |
| dull, foggy, faded, low contrast | contrast stretching | spreads the narrow range over 0 to L−1 |
| separate object from background, binary needed | thresholding | two output values |
| highlight one gray range (bone, tumor, vessel) | gray-level slicing | lights up [A, B] only |
| huge value range (Fourier spectrum) | log | dynamic-range compression |
| white detail inside large dark areas (X-ray) | negative | dark ↔ light |
| compression, data hiding, binary from MSB | bit-plane slicing | keeps only chosen bits |
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.)
| method | formula | one-line meaning |
|---|---|---|
| identity | s = r | no change |
| scaling | s = a·r | a > 1 brighter |
| negative | s = (L−1) − r | dark ↔ light |
| threshold | s = 1 if r > k else 0 | binary, object vs background |
| log | s = c·log(1+r) | expand dark, compress bright |
| inverse log | s = (1/c)·e(r+1) | expand bright, compress dark |
| gamma | s = c·rγ | γ<1 brighter, γ>1 darker |
| stretch | (I−Min)(NewMax−NewMin)/(Max−Min) + NewMin | fill whole range |
| slicing | [A,B] → L−1; else 0 or r | light up one band |
| bit plane | Σ 2n−1·bitn | image = stack of bits |