Denoise | Max

# 3. Strong Bilateral filter (smooths while keeping edges) denoised = denoise_bilateral(denoised, sigma_color=0.3, sigma_spatial=5, multichannel=(image.ndim==3))

if denoised.ndim == 2: coeffs = list(coeffs) coeffs[1:] = threshold_coeffs(coeffs[1:], threshold) denoised = pywt.waverec2(coeffs, wavelet) else: coeffs = list(coeffs) coeffs[1:] = threshold_coeffs(coeffs[1:], threshold) denoised = pywt.waverec(coeffs, wavelet) max denoise

# Apply hard thresholding to detail coefficients def threshold_coeffs(coeff_list, thr): return [pywt.threshold(c, thr, mode='hard') for c in coeff_list] threshold) denoised = pywt.waverec2(coeffs

# Compute universal threshold threshold = sigma * np.sqrt(2 * np.log(denoised.size)) threshold) denoised = pywt.waverec(coeffs

Returns: - denoised: maximally denoised image """ # Ensure float in [0,1] range if image.max() > 1.0: image = image.astype(np.float32) / 255.0 else: image = image.astype(np.float32)