This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MeanGradientError: | |
""" | |
A class used to calculate the Mean Gradient Error (MGE) between two images. | |
Methods | |
------- | |
sobel_x_y_gradients(img): | |
Calculates the gradients in x and y directions using Sobel filters for the input image tensor. | |
calculate_pixel_gradients(grad_x, grad_y): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# for np arrays | |
import numpy as np | |
def minmax(img): | |
return(img-np.min(img) ) / (np.max(img)-np.min(img)) | |
import numpy as np | |
def minmax_percentile(img,perc=2): | |
lower = np.percentile(img,perc) | |
upper = np.percentile(img,100-perc) | |
img[img>upper] = upper |