Q1

Pasted image 20260404182203.png

The image is a 7×7 matrix, meaning the total number of pixels is N×M=49. The intensity values range from 0 to 7, giving us a dynamic range where L=8.

By counting the occurrences of each pixel intensity in the given matrix, we get the base frequency data.


1.1 Histogram

The histogram h(rk) represents the frequency of each pixel intensity rk across the image.

Intensity (rk​) 0 1 2 3 4 5 6 7
Count (h(rk)) 1 4 9 9 8 8 3 7

1.2 Cumulative Histogram

The cumulative histogram H(rk) is calculated by taking the running sum of the histogram frequencies up to each intensity level.

Intensity (rk​) 0 1 2 3 4 5 6 7
Cumulative Count (H(rk)) 1 5 14 23 31 39 42 49

1.3 Histogram Equalization

To perform histogram equalization, we map the original intensity values rk to new values sk using the cumulative probability function. The mapping formula is:

sk=round(L1N×M×H(rk))

Given L1=7 and N×M=49, our multiplier is 749=170.1428.

Mapping Calculations:

Equalized Histogram:

Notice that original intensities 5 and 6 both map to the new intensity 6. Therefore, we add their original frequencies together (8 + 3 = 11).

Intensity (sk​) 0 1 2 3 4 5 6 7
New Count 1 4 9 9 8 0 11 7

1.4 Robust Contrast Stretching (Truncation)

Truncating allows us to ignore outliers (the extreme dark and bright pixels) when setting our new minimum and maximum bounds for the contrast stretch.

Step 1: Calculate Truncation Bounds

Step 2: Contrast Stretching Formula

We map the valid range [2,5] to the full dynamic range [0,7]. Any values below rmin clip to 0, and any values above rmax clip to 7.

Inew=(IMin)NewMaxNewMinMaxMin+NewMinInew=(I2)×7052+0Inew=(I2)×73

Mapping Calculations:

Final Stretched Histogram:

We compile the frequencies of the original pixels based on their newly mapped destinations.

Intensity (sk​) 0 1 2 3 4 5 6 7
New Count 14 0 9 0 0 8 0 18

Q2

Pasted image 20260404185418.png

When a question asks to modify a histogram into a "uniformly distributed" one across a specific interval, it is asking you to perform Histogram Equalization.

Step 1: Calculate Frequencies and Cumulative Frequencies

By counting the occurrences of each intensity (rk) in the matrix, we build our standard histogram h(rk) and cumulative histogram H(rk).

Intensity (rk​) 0 1 2 3 4 5 6 7
Count (h(rk)) 5 4 4 4 2 2 4 0
Cumulative (H(rk)) 5 9 13 17 19 21 25 25

Step 2: Apply the Equalization Formula

Now we map the original intensities (rk) to their new uniform intensities (sk) using the formula:

sk=round(0.28×H(rk))

Step 3: The Modified (Equalized) Histogram

To get the final uniformly distributed histogram, we assign the original pixel counts to their newly calculated intensity levels. Notice that both original intensities 3 and 4 are mapped to the new intensity 5, so their counts are added together (4+2=6).

New Intensity (sk​) 0 1 2 3 4 5 6 7
New Count 0 5 0 4 4 6 2 4

Q3

Pasted image 20260404190802.png

1. First Marked Pixel: (2) at position row 0, column 1

Because this pixel is on the top edge of the image, a 3×3 window centered on it will go out of bounds. The most standard approach in image processing is to assume zero-padding for the out-of-bounds pixels.

The 3×3 neighborhood (with zero-padding on top):

[000122222]

The values in this window are: 0,0,0,1,2,2,2,2,2


2. Second Marked Pixel: (7) at position row 2, column 2

This is an inner pixel, so it has a complete set of 8 surrounding neighbors within the image boundaries. No padding is needed.

The 3×3 neighborhood:

[222173121]

The values in this window are: 2,2,2,1,7,3,1,2,1


Q4

Pasted image 20260404191511.png

First, let's extract the 3×3 neighborhood matrix centered around each pixel.


a) Sobel Operator

The Sobel operator calculates the gradient of the image using two kernels: one for horizontal changes (Gy) and one for vertical changes (Gx).

Gy=[101202101]andGx=[121000121]

The total magnitude is typically calculated as G=Gy2+Gx2 (or approximated by |Gy|+|Gx|).

1. Applying to Pixel (5):

2. Applying to Pixel (7):


b) Laplacian Operator

Got it! Thank you for the clarification. In some textbooks and courses, the "composite" Laplacian is indeed defined as adding the original image back to the standard Laplacian to sharpen it in one step. When you subtract a standard 4-neighbor Laplacian (with a 4 center) from the original image (which acts as a 1 in the center), you get a new kernel with a 5 in the center!

We'll calculate using the composite 4-neighbour 3×3 kernel:

Composite Laplacian Kernel=[010151010]

1. Applying to Pixel (5):

For the pixel at row 1, column 1, we look at its immediate top, bottom, left, and right neighbors.

Calculation:


2. Applying to Pixel (7):

For the pixel at row 1, column 2, we again look at its immediate 4-connected neighbors.

Calculation:

Sum of the 4 neighbors: 6+6+5+5=22

Negate the sum: 22

Center multiplied by 5: 7×(5)=35

Output: 3522= 13