Skip to content

Commit 4ce6b8e

Browse files
Merge pull request #70 from fractal-analytics-platform/misc_fixes
Misc of minor fixes
2 parents c6dac52 + b6ff7ce commit 4ce6b8e

File tree

5 files changed

+82
-25
lines changed

5 files changed

+82
-25
lines changed

pixi.lock

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
22
authors = [{ name = "lorenzo", email = "[email protected]" }]
33
dependencies = [
4-
"streamlit>=1.50.0, <1.51.0",
4+
"streamlit>=1.51.0, <1.52.0",
55
"ngio==0.4.2",
66
"plotly",
77
"matplotlib",

src/fractal_feature_explorer/pages/explore_page/_heat_map_plot.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ def heat_map_component(
7070
df_piv = df_piv.median(numeric_only=True)
7171
elif aggregation == "Counts":
7272
df_piv = df_piv.count()
73+
elif aggregation is None:
74+
st.error("Please select one aggregation")
75+
st.stop()
7376
else:
7477
raise ValueError(f"Unknown aggregation: {aggregation}")
7578

src/fractal_feature_explorer/pages/filters_page/_scatter_filter.py

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ def view_point(point: int, feature_df: pl.DataFrame) -> None:
5656

5757
channels = container.channel_labels
5858
if len(channels) > 1:
59-
channel = st.selectbox(
59+
channel_sel = st.selectbox(
6060
label="Select channel",
6161
options=channels,
6262
index=0,
6363
help="Select the channel to display",
6464
)
65-
channel = channels.index(channel)
65+
channel = channels.index(channel_sel)
6666
else:
6767
channel = 0
6868

@@ -97,7 +97,7 @@ def view_point(point: int, feature_df: pl.DataFrame) -> None:
9797
label="Zoom Factor",
9898
min_value=0.5,
9999
max_value=10.0,
100-
value=1.5,
100+
value=5.0,
101101
step=0.1,
102102
help="Zoom factor for the image",
103103
)
@@ -108,7 +108,28 @@ def view_point(point: int, feature_df: pl.DataFrame) -> None:
108108
index=0,
109109
help="Select the level to display",
110110
)
111-
111+
112+
image_scaling = st.selectbox(
113+
label="Image Scaling",
114+
options=["Metadata", "Min-Max", "Custom"],
115+
index=0,
116+
help="Select the image scaling",
117+
)
118+
119+
vis_meta = image.channels_meta.channels[channel].channel_visualisation
120+
if image_scaling == "Custom":
121+
vis_meta = image.channels_meta.channels[channel].channel_visualisation
122+
max_value = float(max(vis_meta.end * 1.5, 255.))
123+
min_intensity, max_intensity = st.slider(
124+
label="Intensity Range",
125+
min_value=0.,
126+
max_value=max_value,
127+
value=(float(vis_meta.start), float(vis_meta.end)),
128+
)
129+
else:
130+
min_intensity = vis_meta.start
131+
max_intensity = vis_meta.end
132+
112133
try:
113134
image = get_single_label_image(
114135
image_url=point_dict["image_url"],
@@ -120,8 +141,12 @@ def view_point(point: int, feature_df: pl.DataFrame) -> None:
120141
t_slice=t_slice,
121142
show_label=show_label,
122143
zoom_factor=zoom_factor,
144+
scaling_mode=image_scaling,
145+
min_intensity=min_intensity,
146+
max_intensity=max_intensity,
123147
)
124-
st.image(image, use_container_width=True)
148+
149+
st.image(image, width=500)
125150
except Exception as e:
126151
logger.error(f"Error opening image: {e}")
127152
st.error("Error opening image")

src/fractal_feature_explorer/utils/ngio_io_caches.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,27 @@ def _get_label_array(
355355
return label_array
356356

357357

358+
def scale_image_intensity(
359+
image_array: np.ndarray,
360+
scaling_mode: str = "Metadata",
361+
min_intensity: int | float = 0,
362+
max_intensity: int | float = 255,
363+
) -> np.ndarray:
364+
"""
365+
Scale the image intensity based on the selected scaling mode.
366+
"""
367+
if scaling_mode not in ["Metadata", "Min-Max", "Custom"]:
368+
raise ValueError(f"Invalid scaling mode: {scaling_mode}")
369+
370+
if scaling_mode != "Min-Max":
371+
image_array = np.clip(image_array, min_intensity, max_intensity)
372+
373+
min_intensity = image_array.min()
374+
max_intensity = image_array.max()
375+
image_array = (image_array - min_intensity) / (max_intensity - min_intensity)
376+
return image_array * 255
377+
378+
358379
def get_single_label_image(
359380
image_url: str,
360381
ref_label: str,
@@ -365,6 +386,9 @@ def get_single_label_image(
365386
level_path: str = "0",
366387
show_label: bool = True,
367388
zoom_factor: float = 1,
389+
scaling_mode: str = "Metadata",
390+
min_intensity: int | float = 0,
391+
max_intensity: int | float = 255,
368392
) -> np.ndarray:
369393
"""
370394
Get the region of interest from the image url
@@ -382,7 +406,12 @@ def get_single_label_image(
382406
fractal_token=fractal_token,
383407
)
384408
image_array = image_array.squeeze()
385-
image_array = np.clip(image_array, 0, 255)
409+
image_array = scale_image_intensity(
410+
image_array,
411+
scaling_mode=scaling_mode,
412+
min_intensity=min_intensity,
413+
max_intensity=max_intensity,
414+
).astype(np.uint8)
386415

387416
image_rgba = np.empty(
388417
(image_array.shape[0], image_array.shape[1], 4), dtype=np.uint8

0 commit comments

Comments
 (0)