Skip to content

Instantly share code, notes, and snippets.

View ianhi's full-sized avatar

Ian Hunt-Isaak ianhi

View GitHub Profile
@ianhi
ianhi / compare.py
Created October 12, 2022 19:10
Image Comparison Using matplotlib
import matplotlib.pyplot as plt
from mpl_draggable_line import DraggableVLine
def compare_images(img1, img2, ax=None):
img1 = np.asanyarray(img1)
img2 = np.asanyarray(img2)
if not np.all(img1.shape == img2.shape):
raise ValueError("Image shapes must match!")
if ax is None:
ax = plt.gca()
@ianhi
ianhi / interactive_segment.py
Created May 28, 2021 04:14
interactively explore watershed segmentation parameters
%matplotlib widget
from functools import lru_cache
import matplotlib.pyplot as plt
import numpy as np
from mpl_interactions import ipyplot as iplt
from scipy import ndimage as ndi
from skimage.data import binary_blobs
from skimage.feature import peak_local_max
@ianhi
ianhi / jlab.sh
Created December 11, 2020 20:06
setting up jupyterlab environments
jlab-env-basic()
{
conda create -n $1 -c conda-forge python mamba -y
conda activate $1
mamba install -c conda-forge jupyterlab nodejs -y
}
jlab-env-full()
{
conda create -n $1 -c conda-forge python=3.8 mamba -y
conda activate $1
@ianhi
ianhi / imshow_panhandler.py
Last active October 14, 2020 19:44
add right click drag to pan to matplotlib imshow. Now available via https://github.com/ianhi/mpl-interactions
class panhandler:
"""
enable click to pan image.
button determines which button will be used (default right click)
Left: 1
Middle: 2
Right: 3
"""
def __init__(self, fig, button=3):
self.fig = fig
@ianhi
ianhi / imshow_zoom.py
Last active October 14, 2020 19:45 — forked from tacaswell/simp_zoom.py
factory for adding zoom callback to matplotlib imshow - now available via https://github.com/ianhi/mpl-interactions
import matplotlib.pyplot as plt
def zoom_factory(ax,base_scale = 1.1):
"""
parameters
----------
ax : matplotlib axes object
axis on which to implement scroll to zoom
base_scale : float
how much zoom on each tick of scroll wheel
@ianhi
ianhi / lasso.py
Last active May 16, 2020 04:06
class to manage a lasso selector for matplotlib in a jupyter notebook
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import LassoSelector
from matplotlib.path import Path
class image_lasso_selector:
def __init__(self, img, mask_alpha=.75, figsize=(10,10)):
"""
img must have shape (X, Y, 3)
"""