Skip to content

Commit

Permalink
Merge pull request #29 from hi-paris/new_constants
Browse files Browse the repository at this point in the history
Change normalisation constants for Sentinel-TOPS
  • Loading branch information
brash6 authored Apr 19, 2024
2 parents cd663d3 + 8bc973a commit f642b2c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
18 changes: 15 additions & 3 deletions deepdespeckling/merlin/merlin_denoiser.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from glob import glob
import logging
from pathlib import Path
from typing import Tuple
import torch
import os
import numpy as np
from tqdm import tqdm

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)

Expand All @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions deepdespeckling/utils/constants.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

0 comments on commit f642b2c

Please sign in to comment.