Skip to content

Commit bbbf2b0

Browse files
authored
Merge pull request #7 from eigenP/bot/create-marimo-notebook-for-function-showcase
Separate marimo controls into independent cells
2 parents f29ef38 + 3bfaa42 commit bbbf2b0

File tree

1 file changed

+154
-0
lines changed

1 file changed

+154
-0
lines changed
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
import marimo as mo
2+
3+
__generated_with__ = "0.6.15"
4+
5+
app = mo.App()
6+
7+
8+
@app.cell
9+
def __():
10+
import marimo as mo
11+
12+
mo.md(
13+
"""
14+
# Color-coded projection and CLAHE demo
15+
16+
This notebook demonstrates how to use the
17+
`color_coded_projection` and `_my_clahe_` utilities provided in this
18+
repository. We load the sample `cells3d` dataset from scikit-image and
19+
showcase both functions:
20+
21+
* **color_coded_projection** for creating a time/volume color projection
22+
* **_my_clahe_** for applying Contrast Limited Adaptive Histogram Equalization (CLAHE)
23+
24+
Use the controls below to explore different color mappings for the
25+
projection and adjust the CLAHE clip limit to see its effect on the
26+
enhanced slice.
27+
"""
28+
)
29+
30+
31+
@app.cell
32+
def __():
33+
import matplotlib.pyplot as plt
34+
import numpy as np
35+
from skimage import data
36+
37+
from clahe_equalize_adapthist import _my_clahe_
38+
from color_coded_projection import color_coded_projection
39+
40+
return plt, np, data, _my_clahe_, color_coded_projection
41+
42+
43+
@app.cell
44+
def __():
45+
import marimo as mo
46+
47+
colormap_dropdown = mo.ui.dropdown(
48+
label="Projection colormap",
49+
options=[
50+
("Plasma", "plasma"),
51+
("Viridis", "viridis"),
52+
("Inferno", "inferno"),
53+
("Magma", "magma"),
54+
("Cividis", "cividis"),
55+
],
56+
value="plasma",
57+
)
58+
59+
colormap_dropdown
60+
61+
return colormap_dropdown
62+
63+
64+
@app.cell
65+
def __():
66+
import marimo as mo
67+
68+
clahe_clip_slider = mo.ui.slider(
69+
label="CLAHE clip limit",
70+
start=0.01,
71+
stop=0.1,
72+
step=0.005,
73+
value=0.03,
74+
)
75+
76+
clahe_clip_slider
77+
78+
return clahe_clip_slider
79+
80+
81+
@app.cell
82+
def __(data):
83+
cells = data.cells3d()
84+
# Select the membrane channel (index 1)
85+
membrane_stack = cells[:, 1, :, :]
86+
return membrane_stack
87+
88+
89+
@app.cell
90+
def __(membrane_stack, np):
91+
# Normalize the stack to the range [0, 1]
92+
stack_min = membrane_stack.min()
93+
stack_max = membrane_stack.max()
94+
normalized_stack = (membrane_stack - stack_min) / (stack_max - stack_min)
95+
return normalized_stack
96+
97+
98+
@app.cell
99+
def __(color_coded_projection, colormap_dropdown, normalized_stack, np):
100+
projection = color_coded_projection(
101+
normalized_stack.astype(np.float32),
102+
color_map=colormap_dropdown.value,
103+
)
104+
return projection
105+
106+
107+
@app.cell
108+
def __(colormap_dropdown, projection, plt):
109+
fig, ax = plt.subplots(figsize=(5, 5))
110+
ax.imshow(projection)
111+
ax.set_title(
112+
f"Color-coded projection of membrane channel (cmap: {colormap_dropdown.value})"
113+
)
114+
ax.axis("off")
115+
fig.tight_layout()
116+
fig
117+
118+
119+
@app.cell
120+
def __(membrane_stack):
121+
slice_index = 30
122+
original_slice = membrane_stack[slice_index]
123+
return original_slice, slice_index
124+
125+
126+
@app.cell
127+
def __(_my_clahe_, clahe_clip_slider, original_slice):
128+
clahe_slice = _my_clahe_(
129+
original_slice,
130+
clip_limit=float(clahe_clip_slider.value),
131+
nbins=256,
132+
)
133+
return clahe_slice
134+
135+
136+
@app.cell
137+
def __(clahe_clip_slider, clahe_slice, original_slice, plt, slice_index):
138+
fig, axes = plt.subplots(1, 2, figsize=(10, 4))
139+
axes[0].imshow(original_slice, cmap="gray")
140+
axes[0].set_title(f"Original slice {slice_index}")
141+
axes[0].axis("off")
142+
143+
axes[1].imshow(clahe_slice, cmap="gray")
144+
axes[1].set_title(
145+
f"CLAHE enhanced slice (clip_limit={float(clahe_clip_slider.value):.3f})"
146+
)
147+
axes[1].axis("off")
148+
149+
fig.tight_layout()
150+
fig
151+
152+
153+
if __name__ == "__main__":
154+
app.run()

0 commit comments

Comments
 (0)