Я пытался проверить значение MSE следующим образом:
Код: Выделить всё
import numpy as np
from skimage.restoration import denoise_tv_chambolle
import matplotlib.pyplot as plt
from sklearn.metrics import mean_squared_error
from scipy import stats
def create_mask_from_quantiles(image, lower_quantile=0.1, upper_quantile=0.9):
"""
Create a mask based on quantile values to exclude extreme values.
Parameters:
-----------
image : 2D numpy array
Input image
lower_quantile : float
Lower quantile threshold (0-1)
upper_quantile : float
Upper quantile threshold (0-1)
Returns:
--------
mask : 2D boolean array
True for values within quantile range
"""
lower_thresh = np.quantile(image, lower_quantile)
upper_thresh = np.quantile(image, upper_quantile)
return (image >= lower_thresh) & (image 0.1))
# Normalize to 0-1 range
test_image = (test_image - test_image.min()) / (test_image.max() - test_image.min())
return test_image
# Generate test data with different wind conditions
test_image = generate_test_data(
size=100,
noise_level=0.1,
wind_direction=45, # 45 degree wind direction
wind_speed=1.5 # Moderate wind speed
)
multiplier = 2
# Find optimal weight and denoise
optimal_weight, results = tune_tv_chambolle(
test_image,
lower_quantile=0.2,
upper_quantile=0.8,
n_weights=15,
multiplier=multiplier,
)
# Apply final denoising with optimal weight
final_denoised = denoise_tv_chambolle(test_image, weight=optimal_weight,
channel_axis=None,
)
# Compare original vs denoised for masked region
mask = results['mask']
original_std = np.std(test_image[mask])
denoised_std = np.std(final_denoised[mask])
noise_reduction = (1 - denoised_std/original_std) * 100
print(f"Optimal weight: {optimal_weight:.4f}")
print(f"Noise reduction in masked region: {noise_reduction:.1f}%")
weight_max = Noise_std*2
Оптимально вес: 0,0572
Снижение шума в замаскированной области: 20,8%

weight_max = Noise_std*3
Оптимальный вес: 0,0259
Снижение шума в замаскированной области: 24,9%

weight_max = Noise_std*4
Оптимальный вес: 0,0436
Снижение шума в замаскированной области: 25,2 %

Вопрос
Кажется, Noise_std*3 получает неправильный оптимальный вес согласно изображению. Как установить правильный диапазон веса, чтобы получить оптимизированный ТВ-фильтр?
Подробнее здесь: https://stackoverflow.com/questions/793 ... -tv-filter
Мобильная версия