Skip to content

Instantly share code, notes, and snippets.

View kwsp's full-sized avatar

Taylor kwsp

  • Washington University in St. Louis
View GitHub Profile
from concurrent.futures import ThreadPoolExecutor
from pathlib import Path
from tqdm import tqdm
import cv2
import matplotlib.pyplot as plt
import numpy as np
def find_best_img_match(target_img: np.array, imgpaths: list[Path]):
@kwsp
kwsp / align_OCT.py
Last active February 19, 2025 22:33
"""
Convert exported, rect OCT images to aligned rect and radial, save as NRRD files.
1. Change the `input_folder` to point to the directory containing images.
2. Change the row range used for correlation by changing `rowStart` and `rowEnd` to make sure they only include the tubing and avoid any tissue in this window.
Install dependencies:
```
python3 -m pip install numpy matplotlib pillow pynrrd tqdm opencv-python
@kwsp
kwsp / to_nrrd.py
Created January 23, 2025 22:27
to_nrrd.py
"""
dependencies: numpy pillow pynrrd tqdm
"""
from PIL import Image
from pathlib import Path
from tqdm import tqdm
import nrrd
import numpy as np
@kwsp
kwsp / CopyToTargetDir.cmake
Last active December 31, 2024 23:27
Copy resources from source dir to CMake multi-config build directory
function(copy_to_target_dir target resource)
add_custom_command(
TARGET ${target} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
"$<TARGET_PROPERTY:${target},SOURCE_DIR>/${resource}"
"$<TARGET_FILE_DIR:${target}>/${resource}"
)
endfunction()
copy_to_target_dir(${EXE_NAME} shaders)
@kwsp
kwsp / bin_io.hpp
Last active September 9, 2024 17:05
#include <iostream>
#include <fstream>
#include <armadillo>
// T is the type of value stored in the binary file.
template <typename T>
auto load_bin(const fs::path &filename) -> arma::Mat<T> {
std::ifstream file(filename, std::ios::binary | std::ios::ate);
@kwsp
kwsp / setup_gpg_git.md
Created August 14, 2024 15:36
Setup GPG for git

Windows

I use git from scoop. Open git bash to access the gpg binary. If you install gpg from scoop it will not work as git doesn't know about it.

Import existing private key

gpg --import private.key
@kwsp
kwsp / debug_gh_actions.md
Created July 11, 2024 08:12
Trick to debug VCPKG build errors in GitHub Actions
jobs:
  build:
    steps:
      - name: Export GitHub Actions cache environment variables
        uses: actions/github-script@v7
 with:
"""
typed_mat_mixin.py provides a mixin `InitMixin` that tries
to generate a `.init` method to a typed Dataclass to automatically
deserialize .mat files exported from MATLAB to a Python Dataclass.
Supported types:
- strings
- int, float, np.uint8, and most np typedefs
- np.ndarray (1D and 2D tested)
- Type arrays as np.array[ndims, dtype]
@kwsp
kwsp / fft_registration.py
Last active February 2, 2025 14:20
FFT-based translation, rotation, and scale-invariant image registration
"""
B. S. Reddy and B. N. Chatterji, “An FFT-based technique for translation, rotation, and scale-invariant image registration,” IEEE Transactions on Image Processing, vol. 5, no. 8, pp. 1266–1271, Aug. 1996, doi: 10.1109/83.506761.
Implemented in Numpy/OpenCV and Numpy/Scikit-Image
The OpenCV version is about 4 times faster than the Scikit-Image version.
"""
# Numpy/OpenCV implementation
import cv2
from scipy import signal
import numpy as np
import cv2
def polar2cart(img: np.ndarray):
"""
Convert image (B-scan) from Polar coordinates to Cartesian coordinates
"""
# Resize image to square first