-
Notifications
You must be signed in to change notification settings - Fork 0
Separate marimo controls into independent cells #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| import marimo as mo | ||
|
|
||
| __generated_with__ = "0.6.15" | ||
|
|
||
| app = mo.App() | ||
|
|
||
|
|
||
| @app.cell | ||
| def __(): | ||
| import marimo as mo | ||
|
|
||
| mo.md( | ||
| """ | ||
| # Color-coded projection and CLAHE demo | ||
|
|
||
| This notebook demonstrates how to use the | ||
| `color_coded_projection` and `_my_clahe_` utilities provided in this | ||
| repository. We load the sample `cells3d` dataset from scikit-image and | ||
| showcase both functions: | ||
|
|
||
| * **color_coded_projection** for creating a time/volume color projection | ||
| * **_my_clahe_** for applying Contrast Limited Adaptive Histogram Equalization (CLAHE) | ||
|
|
||
| Use the controls below to explore different color mappings for the | ||
| projection and adjust the CLAHE clip limit to see its effect on the | ||
| enhanced slice. | ||
| """ | ||
| ) | ||
|
|
||
|
|
||
| @app.cell | ||
| def __(): | ||
| import matplotlib.pyplot as plt | ||
| import numpy as np | ||
| from skimage import data | ||
|
|
||
| from clahe_equalize_adapthist import _my_clahe_ | ||
| from color_coded_projection import color_coded_projection | ||
|
|
||
| return plt, np, data, _my_clahe_, color_coded_projection | ||
|
|
||
|
|
||
| @app.cell | ||
| def __(): | ||
| import marimo as mo | ||
|
|
||
| colormap_dropdown = mo.ui.dropdown( | ||
| label="Projection colormap", | ||
| options=[ | ||
| ("Plasma", "plasma"), | ||
| ("Viridis", "viridis"), | ||
| ("Inferno", "inferno"), | ||
| ("Magma", "magma"), | ||
| ("Cividis", "cividis"), | ||
| ], | ||
| value="plasma", | ||
| ) | ||
|
|
||
| colormap_dropdown | ||
|
|
||
| return colormap_dropdown | ||
|
|
||
|
|
||
| @app.cell | ||
| def __(): | ||
| import marimo as mo | ||
|
|
||
| clahe_clip_slider = mo.ui.slider( | ||
| label="CLAHE clip limit", | ||
| start=0.01, | ||
| stop=0.1, | ||
| step=0.005, | ||
| value=0.03, | ||
| ) | ||
|
|
||
| clahe_clip_slider | ||
|
|
||
| return clahe_clip_slider | ||
|
|
||
|
|
||
| @app.cell | ||
| def __(data): | ||
| cells = data.cells3d() | ||
| # Select the membrane channel (index 1) | ||
| membrane_stack = cells[:, 1, :, :] | ||
| return membrane_stack | ||
|
|
||
|
|
||
| @app.cell | ||
| def __(membrane_stack, np): | ||
| # Normalize the stack to the range [0, 1] | ||
| stack_min = membrane_stack.min() | ||
| stack_max = membrane_stack.max() | ||
| normalized_stack = (membrane_stack - stack_min) / (stack_max - stack_min) | ||
| return normalized_stack | ||
|
|
||
|
|
||
| @app.cell | ||
| def __(color_coded_projection, colormap_dropdown, normalized_stack, np): | ||
| projection = color_coded_projection( | ||
| normalized_stack.astype(np.float32), | ||
| color_map=colormap_dropdown.value, | ||
| ) | ||
| return projection | ||
|
|
||
|
|
||
| @app.cell | ||
| def __(colormap_dropdown, projection, plt): | ||
| fig, ax = plt.subplots(figsize=(5, 5)) | ||
| ax.imshow(projection) | ||
| ax.set_title( | ||
| f"Color-coded projection of membrane channel (cmap: {colormap_dropdown.value})" | ||
| ) | ||
| ax.axis("off") | ||
| fig.tight_layout() | ||
| fig | ||
|
|
||
|
|
||
| @app.cell | ||
| def __(membrane_stack): | ||
| slice_index = 30 | ||
| original_slice = membrane_stack[slice_index] | ||
| return original_slice, slice_index | ||
|
|
||
|
|
||
| @app.cell | ||
| def __(_my_clahe_, clahe_clip_slider, original_slice): | ||
| clahe_slice = _my_clahe_( | ||
| original_slice, | ||
| clip_limit=float(clahe_clip_slider.value), | ||
| nbins=256, | ||
| ) | ||
| return clahe_slice | ||
|
|
||
|
|
||
| @app.cell | ||
| def __(clahe_clip_slider, clahe_slice, original_slice, plt, slice_index): | ||
| fig, axes = plt.subplots(1, 2, figsize=(10, 4)) | ||
| axes[0].imshow(original_slice, cmap="gray") | ||
| axes[0].set_title(f"Original slice {slice_index}") | ||
| axes[0].axis("off") | ||
|
|
||
| axes[1].imshow(clahe_slice, cmap="gray") | ||
| axes[1].set_title( | ||
| f"CLAHE enhanced slice (clip_limit={float(clahe_clip_slider.value):.3f})" | ||
| ) | ||
| axes[1].axis("off") | ||
|
|
||
| fig.tight_layout() | ||
| fig | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| app.run() | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new marimo demo imports
clahe_equalize_adapthistandcolor_coded_projectionas top‑level modules, but those files live one directory above the notebook and are not part of an installed package. Running the app viamarimo run notebooks/color_projection_clahe_demo.py(orpython notebooks/...) setssys.path[0]tonotebooks, so the repo root is no longer on the import path and both imports raiseModuleNotFoundError, preventing the demo from starting. Consider using a relative import (e.g.,from ..color_coded_projection import ...inside a package or prepending the project root tosys.path) so the example runs out of the box.Useful? React with 👍 / 👎.