Skip to content

Instantly share code, notes, and snippets.

View JavierGSanchez's full-sized avatar
🏠
Working from home

Javier G. Sanchez JavierGSanchez

🏠
Working from home
  • Seattle
View GitHub Profile
@tayden
tayden / skimage-exposure-match-histograms-with-masked-array.py
Last active June 19, 2024 16:25
Scikit-Image histogram matching doesn't work on numpy masked arrays. This gist is a workaround for this issue. It shows how to do histogram matching when you have an image and need to exclude certain values from being considered as part of the image histogram.
from skimage import io, exposure
import numpy as np
# Histogram matching with masked image
def match_histograms(image, reference, image_mask, fill_value=0):
masked_image = np.ma.array(image, mask=image_mask)
matched = np.ma.array(np.empty(image.shape, dtype=image.dtype),
mask=image_mask, fill_value=fill_value)
for channel in range(masked_image.shape[-1]):