Open Dream-gpc opened 2 years ago
Hello Dream-gpc and thank you for your kind feedback.
NL-Ridge has the advantage of being an homogeneous function meaning that f(lambda x, lambda sigma) = lambda f(x, sigma) for lambda > 0. If your input x is an uint16 image, I recommend normalizing it on [0, 1] with type float32 first before applying the denoiser. So you want to do: f(lambda x, lambda sigma) / lambda with lambda = 1 / max_value.
In practice, you can use skimage and numpy to read, convert and save your denoised image. Here is the kind of script you can use in your case: ############################### import torch import numpy from skimage.io import imsave, imread from nlridge import NLRidge import argparse import numpy as np
parser = argparse.ArgumentParser() parser.add_argument("--sigma", type=float, dest="sigma", help="Standard deviation of the noise (noise level). Should be between 0 and 50.", default=15) parser.add_argument("--in", type=str, dest="path_in", help="Path to the image to denoise (PNG or JPEG).", default="./test_images/barbara.png") parser.add_argument("--out", type=str, dest="path_out", help="Path to save the denoised image.", default="./denoised.png") args = parser.parse_args()
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
img_noisy = imread(args.path_in) max_value = img_noisy.max()
img_noisy_torch = torch.from_numpy(img_noisy).view(1, 1, *img_noisy.shape).float().to(device)
model = NLRidge(7, 7, 18, 55, 37, 4)
den = model(img_noisy_torch / max_value, args.sigma / max_value) * max_value
den_uint16 = den.view(*img_noisy.shape).numpy().astype(np.uint16)
imsave(args.path_out, den_uint16) ################################
Finally, If you use a real-world noisy image (not artificial Gaussian noise), in order to avoid errors, I recommend changing the line 77 in denoise1 function in nlridge.py: theta = torch.cholesky_solve(YtY - n * sigma2 Ik, torch.linalg.cholesky(YtY)) by: theta = torch.cholesky_solve(YtY - n sigma2 Ik, torch.linalg.cholesky(YtY + n sigma*2 Ik)) I explain why in a coming paper...
Thanks for the answer.
Good job.
I'm glad that the code can work normally, but I find it is based on unit8 images. If I want to apply the code to unit16 images, such as raw, how can I change the parameters of the file? Look forward to your reply.