Skip to content

Instantly share code, notes, and snippets.

View simon-donike's full-sized avatar

Simon Donike simon-donike

View GitHub Profile
@simon-donike
simon-donike / MGE.py
Last active July 10, 2023 11:03
Mean Gradient Error - PyTorch
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):
@simon-donike
simon-donike / arrays_stretching_np_torch.py
Last active August 9, 2023 11:03
MinMax and percentile MinMax stretching for numpy arrays
# 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