You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using greyscale pngs which have been contrast stretched to have pixel values in range 0-255. I have a value for test_psnr, but when I independently calculate this value I get a different result. However I note that in your implementation of PSNR the max_val is set to 1, whereas elsewhere implementations use 255. Also in the enhance method you multiply by 255 then clip to 0,255, which is at odds with using max_val is set to 1? My functions are below: can you advise what is the issue resulting in the differences?
def contrast_stretch(img: np.array) -> np.array:
"""Contrast stretch an image
Return pixels in range 0 to 255.
Parameters
----------
img : np.array
Image to be contrast stretched
Returns
-------
np.array
Contrast stretched image
"""
img_min = img.min()
img_max = img.max()
return (img - img_min) / (img_max - img_min)*255
def psnr(img1: np.array, img2: np.array, max_value: float = 255.0) -> float:
"""
Compute the PSNR between two images.
For 8bit greyscale max value is 255 and min is zero.
"""
mse = np.mean((img1 - img2) ** 2)
return round(20 * math.log10(max_value / math.sqrt(mse)), 1)
The text was updated successfully, but these errors were encountered:
Thanks for catching the bug in the enhance method. I haven't updated this in a while but I was planning on scrapping the metrics and using torchmetrics instead (i.e. SSIM, MSSIM, MSE, PSNR) since they work in distributed training settings.
I am using greyscale pngs which have been contrast stretched to have pixel values in range 0-255. I have a value for test_psnr, but when I independently calculate this value I get a different result. However I note that in your implementation of PSNR the max_val is set to 1, whereas elsewhere implementations use 255. Also in the
enhance
method you multiply by 255 then clip to 0,255, which is at odds with using max_val is set to 1? My functions are below: can you advise what is the issue resulting in the differences?The text was updated successfully, but these errors were encountered: