Skip to content

Instantly share code, notes, and snippets.

View BoMeyering's full-sized avatar
🏠
Debugging Pytorch code...

Bo Meyering BoMeyering

🏠
Debugging Pytorch code...
View GitHub Profile
@BoMeyering
BoMeyering / four_point_transforms.py
Last active June 1, 2024 04:11
Performs a 4 point transform on an image using the linear sum assignment to find the closest corners. Useful for ROI extractions.
# Four Point Image Transforms
# BoMeyering 2024
import numpy as np
import cv2
from scipy.spatial import distance_matrix
from scipy.optimize import linear_sum_assignment
from typing import Tuple
def order_points(pts: np.ndarray, img_shape: Tuple[int, int]) -> np.ndarray:
@BoMeyering
BoMeyering / welford_method.py
Created May 4, 2024 03:26
Calculation of running mean and standard deviation of image sets in Pytorch. Online computation and numerically stable for large datasets.
# Welfords method for calculating mean and variance
# BoMeyering 2024
import torch
import sys
class WelfordCalculator:
def __init__(self):
self.M = torch.zeros(3, dtype=torch.float64)
self.M_old = torch.zeros(3, dtype=torch.float64)
self.S = torch.zeros(3, dtype=torch.float64)
@BoMeyering
BoMeyering / export_exif.py
Created December 4, 2023 17:05
Script to eport exif datat from images in a directory into a .csv file
import os
import numpy as np
import pandas as pd
from exif import Image
DIRECTORY = "exif_photos" # Set top directory here
res = []