Py.Cafe

maartenbreddels/

stackview-clusterplot

Image Segmentation and Analysis Dashboard using stackview

DocsPricing
  • app.py
  • requirements.txt
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import pandas as pd
import numpy as np
import stackview
import pandas as pd
from skimage.measure import regionprops_table
from skimage.io import imread
from skimage.filters import threshold_otsu
from skimage.measure import label
import matplotlib.pyplot as plt

print(stackview.__version__)

image = imread('blobs.tif')

# segment image
thresh = threshold_otsu(image)
binary_image = image > thresh
labeled_image = label(binary_image)
properties = regionprops_table(labeled_image, properties=['centroid', 'area', 'feret_diameter_max', 'minor_axis_length', 'major_axis_length'])

df = pd.DataFrame(properties)
df["aspect_ratio"] = df['major_axis_length'] / df['minor_axis_length']

num_objects = df.shape[0]
pre_selection = np.zeros(num_objects)
pre_selection[:int(num_objects/2)] = 1

pre_selection2 = np.zeros(num_objects)
pre_selection2[::2] = 1

stackview.clusterplot(image=image,
                     labels=labeled_image,
                     df=df,
                     column_x="area",
                     column_y="aspect_ratio", 
                     zoom_factor=1.6,
                     alpha=0.7)