diff --git a/deepdespeckling/merlin/merlin_denoiser.py b/deepdespeckling/merlin/merlin_denoiser.py index 2700603..92ae78e 100644 --- a/deepdespeckling/merlin/merlin_denoiser.py +++ b/deepdespeckling/merlin/merlin_denoiser.py @@ -1,6 +1,7 @@ from glob import glob import logging from pathlib import Path +from typing import Tuple import torch import os import numpy as np @@ -8,7 +9,7 @@ from deepdespeckling.denoiser import Denoiser from deepdespeckling.model import Model -from deepdespeckling.utils.constants import M, m +from deepdespeckling.utils.constants import M, m, M_s, m_s from deepdespeckling.utils.utils import (denormalize_sar_image, load_sar_image, save_image_to_npy_and_png, symetrise_real_and_imaginary_parts, create_empty_folder_in_directory) @@ -28,6 +29,7 @@ def __init__(self, model_name, symetrise, **params): super().__init__(**params) self.model_name = model_name self.symetrise = symetrise + self.M, self.m = self.init_min_max_norm_values() self.weights_path = self.init_model_weights_path() def init_model_weights_path(self) -> str: @@ -51,6 +53,16 @@ def init_model_weights_path(self) -> str: return model_weights_path + def init_min_max_norm_values(self) -> Tuple[float, float]: + """Initialize min and max values for normalization depending on model name + + Returns: + Tuple[float, float]: Max and min values for SAR image normalization + """ + if self.model_name == "Sentinel-TOPS": + return M_s, m_s + return M, m + def load_model(self, patch_size: int) -> Model: """Load model with given weights @@ -213,9 +225,9 @@ def denoise_image(self, noisy_image: np.array, patch_size: int, stride_size: int imag_to_denoise, device=self.device, dtype=torch.float32) real_to_denoise = (torch.log(torch.square( - real_to_denoise)+1e-3)-2*m)/(2*(M-m)) + real_to_denoise)+1e-3)-2*self.m)/(2*(self.M-self.m)) imag_to_denoise = (torch.log(torch.square( - imag_to_denoise)+1e-3)-2*m)/(2*(M-m)) + imag_to_denoise)+1e-3)-2*self.m)/(2*(self.M-self.m)) denoised_image_real_part = self.denoise_image_kernel( real_to_denoise, denoised_image_real_part, x, y, patch_size, model) diff --git a/deepdespeckling/utils/constants.py b/deepdespeckling/utils/constants.py index 0adb93c..f97f468 100644 --- a/deepdespeckling/utils/constants.py +++ b/deepdespeckling/utils/constants.py @@ -1,7 +1,13 @@ +import numpy as np + # Global maximum and minimum values obtained empirically and used to normalize SAR images M = 10.089038980848645 m = -1.429329123112601 +# Sentinel-TOPS global maximum and minimum constants used to normalize SAR images +M_s = 12.385 +m_s = -np.log(0.001) + # Must be a power of 2 lower than min(height, width) of the image to despeckle # Default to 256 as the trained spotlight and stripmap models stored in merlin/saved_model PATCH_SIZE = 256 diff --git a/setup.py b/setup.py index db896e8..2c5aea5 100644 --- a/setup.py +++ b/setup.py @@ -40,6 +40,6 @@ name='deepdespeckling', packages=find_packages(include=['deepdespeckling', 'deepdespeckling.*']), url='https://github.com/hi-paris/deepdespeckling', - version='0.6', + version='0.7', zip_safe=False, )