Mu Transform

Mu transform is an image enhancement technique. In this post, we will introduce 3 variants of mu transform.

In image processing, Mu Transform (μ-Transform) is a non-linear transformation used to enhance image contrast, particularly in applications like medical imaging and remote sensing. It is a type of contrast enhancement technique that adjusts pixel intensities to improve visibility of details in an image.

1. Generalized Mu Transform

$$
\begin{equation}
I^{\prime} = \frac{I^{\mu}}{I^{\mu} + \lambda(1 - I)^{\mu}}
\end{equation}
$$

where:

  • $I$ is the normalized input pixel intensity (ranging from 0 to 1).
  • $I^{\prime}$ is the transformed output pixel intensity.
  • $\mu$ is the transformation parameter that controls the contrast enhancement.
  • $\lambda$ controls the balance between bright and dark regions. When $\lambda > 1$, it increases contrast in bright regions. When $\lambda < 1$, it enhances dark regions.

2. Log-Mu Transform

This variant combines the logarithmic transformation with the Mu Transform to enhance details in both dark and bright regions:

$$
\begin{equation}
I^{\prime} = log(1 + c \times \frac{I^{\mu}}{I^{\mu} + (1 - I)^{\mu}})
\end{equation}
$$

where

  • $c$ is a scaling constant.
  • This variant is useful for HDR (High Dynamic Range) imaging.

3. Adaptive Mu Transform

Instead of using a fixed $\mu$ for the entire image, an adaptive version computes $\mu$ based on local image statistics (like mean or variance). A common approach is:

$$
\begin{equation}
\mu(x, y) = \alpha + \beta \times Var(I_{local})
\end{equation}
$$

where:

  • $\alpha$ and $\beta$ are user-defined parameters.
  • $Var(I_{local})$ is the local variance around pixel $(x,y)$.
  • This allows spatially adaptive contrast enhancement, which is useful in medical imaging and low-light conditions.

4. Example

exmaple.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import cv2
import numpy as np
import matplotlib.pyplot as plt

def apply_mu_transform(image, transform_func, **kwargs):
"""Applies Mu Transform to each RGB channel separately."""
channels = cv2.split(image) # Split into R, G, B
transformed_channels = [transform_func(ch, **kwargs) for ch in channels]
return cv2.merge(transformed_channels) # Merge back to RGB

def generalized_mu_transform(image, mu=2.0, lambda_=1.0):
"""Generalized Mu Transform for RGB images."""
I = image.astype(np.float32) / 255.0 # Normalize
I_transformed = (I**mu) / (I**mu + lambda_ * (1 - I)**mu)
return (I_transformed * 255).astype(np.uint8) # Convert back

def log_mu_transform(image, mu=2.0, c=1.0):
"""Log-Mu Transform for RGB images."""
I = image.astype(np.float32) / 255.0
I_mu = (I**mu) / (I**mu + (1 - I)**mu)
I_transformed = np.log1p(c * I_mu)
I_transformed /= np.max(I_transformed) # Normalize
return (I_transformed * 255).astype(np.uint8)

def adaptive_mu_transform(image, alpha=1.0, beta=10.0):
"""Adaptive Mu Transform for RGB images (local contrast-based)."""
I = image.astype(np.float32) / 255.0
kernel_size = 7
mean_local = cv2.blur(I, (kernel_size, kernel_size))
variance_local = cv2.blur(I**2, (kernel_size, kernel_size)) - mean_local**2
mu_adaptive = alpha + beta * variance_local
I_transformed = (I**mu_adaptive) / (I**mu_adaptive + (1 - I)**mu_adaptive)
return (I_transformed * 255).astype(np.uint8)

# Load RGB image
image = cv2.imread("save.jpg")
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) # Convert BGR to RGB

# Apply Mu Transforms
gen_mu_img = apply_mu_transform(image, generalized_mu_transform, mu=3.0, lambda_=1.0)
log_mu_img = apply_mu_transform(image, log_mu_transform, mu=3.0, c=2.0)
adaptive_mu_img = apply_mu_transform(image, adaptive_mu_transform, alpha=1.0, beta=5.0)

# Plot results in a 2x2 grid
plt.figure(figsize=(10, 10))

plt.subplot(2, 2, 1)
plt.imshow(image)
plt.title("Original")
plt.axis("off")

plt.subplot(2, 2, 2)
plt.imshow(gen_mu_img)
plt.title("Generalized Mu Transform")
plt.axis("off")

plt.subplot(2, 2, 3)
plt.imshow(log_mu_img)
plt.title("Log-Mu Transform")
plt.axis("off")

plt.subplot(2, 2, 4)
plt.imshow(adaptive_mu_img)
plt.title("Adaptive Mu Transform")
plt.axis("off")

plt.tight_layout() # Adjust layout for better spacing
plt.show()

Author

Joe Chu

Posted on

2025-02-04

Updated on

2025-02-04

Licensed under

Comments