# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

import sys
sys.path.append("..")

import spotlob
from spotlob.process_opencv import SimpleReader, BinaryThreshold, ContourFinder, GaussianPreprocess, GreyscaleConverter, draw_contours
import cv2
import numpy

filename = "inner-outer-demo.png"

reader = SimpleReader()
converter = GreyscaleConverter()
preprocessor = GaussianPreprocess(ksize=1)
binarizer = BinaryThreshold(threshold=100)

s1 = spotlob.Spim.from_file(filename, cached=True).read(reader).convert(converter).preprocess(preprocessor).binarize(binarizer)

finder = ContourFinder(mode="all")
modes = sorted(finder.parameters[0].options)

import matplotlib.pyplot as plt

# +
nh = int(numpy.ceil(len(modes)/2))
size = 5
fig, axes = plt.subplots(nh,2, figsize=(2*size, size*nh))

for mode, ax in zip(modes, axes.flatten()):
    finder = ContourFinder(mode=mode)
    s2 = s1.extract_features(finder)
    
    contours = s2.metadata['contours']
    
    cimg = cv2.cvtColor(s2.image, cv2.COLOR_GRAY2RGB)
    img = draw_contours(cimg, contours, color=(255,0,0), thickness=3)
    ax.imshow(img)
    ax.text(2,-10,mode)
    ax.axis('off')



StarcoderdataJupyterScriptsDedupFiltered