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)