Modulus maxima

60 views
Skip to first unread message

sofia moroni

unread,
Jan 25, 2023, 8:57:50 AM1/25/23
to PyWavelets
Hi, 
I am trying to apply an image fusion algoruthm by applying modulus maxima method to the coefficients of the DWT. Could anyone tell me which kind of basis I should use to decompose an image?
Can anyome tell me how can I implement the modulus maxima method on python?

Thank you

Gautam Sinha

unread,
Jan 26, 2023, 3:22:28 AM1/26/23
to PyWavelets
Hi Sofia,

I would personally recommend to try out the Matlab's image fusion method before jumping to python. The Modulus Maxima method has not been implemented so you might need to hardcode the algorithm. 
Regarding choice of basis, it would make sense to use mexican hat wavelet or DoG as wavelet basis (due to some maxima convergence relation given in Chapter 5 of Mallat's book). 

Deepu

unread,
May 22, 2023, 2:04:29 AM5/22/23
to PyWavelets
When decomposing an image using the Discrete Wavelet Transform (DWT) for the purpose of image fusion, it is common to use orthogonal wavelet bases such as Daubechies (db), Symlets (sym), or Coiflets (coif). These wavelet families provide good localization properties and are widely used in image processing applications.

To implement the modulus maxima method in Python, you can follow these steps:

1. Import the necessary libraries:
```python
import numpy as np
import pywt
from scipy.ndimage.filters import maximum_filter
```

2. Load and convert the input images to grayscale:
```python
image1 = ...  # Load image 1
image2 = ...  # Load image 2

# Convert images to grayscale
image1_gray = np.mean(image1, axis=2)
image2_gray = np.mean(image2, axis=2)
```

3. Perform the DWT decomposition on both images:
```python
wavelet = 'db4'  # Choose the wavelet type
level = 5  # Choose the decomposition level

# Perform DWT decomposition on image 1
coeffs1 = pywt.wavedec2(image1_gray, wavelet, level=level)

# Perform DWT decomposition on image 2
coeffs2 = pywt.wavedec2(image2_gray, wavelet, level=level)
```

4. Calculate the modulus maxima:
```python
modulus_maxima = []

# Iterate over the decomposition levels
for i in range(level):
    # Calculate the modulus maxima for each level
    maxima = maximum_filter(coeffs1[i], size=(3, 3))  # Adjust the filter size if needed
    modulus_maxima.append(maxima)
```

5. Fuse the coefficients using the modulus maxima:
```python
fused_coeffs = []

# Iterate over the decomposition levels
for i in range(level):
    # Fuse the coefficients using modulus maxima
    fused_coeffs.append(np.where(modulus_maxima[i], coeffs1[i], coeffs2[i]))

# Add the approximation coefficient from the last level
fused_coeffs.append(coeffs1[level])

# Reconstruct the fused image
fused_image = pywt.waverec2(fused_coeffs, wavelet)
```

6. Display or save the fused image as desired:
```python
import matplotlib.pyplot as plt

plt.imshow(fused_image, cmap='gray')
plt.axis('off')
plt.show()
```

This is a basic implementation of the modulus maxima method for image fusion using the DWT. You can modify the code according to your specific requirements and experiment with different wavelet families, decomposition levels, and filter sizes for the modulus maxima operation.

Note that this implementation assumes you have already installed the required packages (`numpy`, `pywt`, `scipy`). If not, you can install them using `pip install numpy pywavelets scipy`.

I hope this helps you get started with implementing the modulus maxima method in Python for image fusion.
Reply all
Reply to author
Forward
0 new messages