Spaces:
Running on Zero
Running on Zero
download
Browse files
app.py
CHANGED
|
@@ -133,17 +133,22 @@ def generate_colorbar_preview(color_name):
|
|
| 133 |
rgb[..., 1] = high_half
|
| 134 |
rgb[..., 2] = low_half
|
| 135 |
else:
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
if color_name == "Red Hot":
|
| 140 |
-
rgb[..., 0] =
|
| 141 |
-
rgb[..., 1] =
|
| 142 |
-
rgb[..., 2] =
|
| 143 |
elif color_name == "Cyan Hot":
|
| 144 |
-
rgb[..., 2] =
|
| 145 |
-
rgb[..., 1] =
|
| 146 |
-
rgb[..., 0] =
|
| 147 |
|
| 148 |
elif color_name == "Green (GFP)": rgb[..., 1] = gradient
|
| 149 |
elif color_name == "Red (RFP)": rgb[..., 0] = gradient
|
|
@@ -188,17 +193,22 @@ def apply_pseudocolor(image_np, color_name="Grayscale"):
|
|
| 188 |
rgb[..., 1] = high_half
|
| 189 |
rgb[..., 2] = low_half
|
| 190 |
else:
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
if color_name == "Red Hot":
|
| 195 |
-
rgb[..., 0] =
|
| 196 |
-
rgb[..., 1] =
|
| 197 |
-
rgb[..., 2] =
|
| 198 |
elif color_name == "Cyan Hot":
|
| 199 |
-
rgb[..., 2] =
|
| 200 |
-
rgb[..., 1] =
|
| 201 |
-
rgb[..., 0] =
|
| 202 |
|
| 203 |
elif color_name == "Green (GFP)": rgb[..., 1] = norm_img
|
| 204 |
elif color_name == "Red (RFP)": rgb[..., 0] = norm_img
|
|
@@ -615,7 +625,7 @@ with gr.Blocks(theme=gr.themes.Soft(), css=CUSTOM_CSS) as demo:
|
|
| 615 |
t2i_btn = gr.Button("Generate", variant="primary")
|
| 616 |
with gr.Column(scale=2):
|
| 617 |
# Changed: Image to Gallery
|
| 618 |
-
t2i_gallery_out = gr.Gallery(label="Generated Images", columns=3, height="auto")
|
| 619 |
with gr.Row(equal_height=True):
|
| 620 |
with gr.Column(scale=2):
|
| 621 |
t2i_color = gr.Dropdown(choices=COLOR_MAPS, value="Green (GFP)", label="Pseudocolor (Adjust after generation)")
|
|
|
|
| 133 |
rgb[..., 1] = high_half
|
| 134 |
rgb[..., 2] = low_half
|
| 135 |
else:
|
| 136 |
+
step_1_red = np.clip(gradient * 3, 0, 1)
|
| 137 |
+
step_2_red = np.clip((gradient - 0.333) * 3, 0, 1)
|
| 138 |
+
step_3_red = np.clip((gradient - 0.666) * 3, 0, 1)
|
| 139 |
+
|
| 140 |
+
step_1_cyan = np.clip(gradient / 0.375, 0, 1)
|
| 141 |
+
step_2_cyan = np.clip((gradient - 0.375) / 0.5, 0, 1)
|
| 142 |
+
step_3_cyan = np.clip((gradient - 0.875) / 0.125, 0, 1)
|
| 143 |
+
|
| 144 |
if color_name == "Red Hot":
|
| 145 |
+
rgb[..., 0] = step_1_red
|
| 146 |
+
rgb[..., 1] = step_2_red
|
| 147 |
+
rgb[..., 2] = step_3_red
|
| 148 |
elif color_name == "Cyan Hot":
|
| 149 |
+
rgb[..., 2] = step_1_cyan
|
| 150 |
+
rgb[..., 1] = step_2_cyan
|
| 151 |
+
rgb[..., 0] = step_3_cyan
|
| 152 |
|
| 153 |
elif color_name == "Green (GFP)": rgb[..., 1] = gradient
|
| 154 |
elif color_name == "Red (RFP)": rgb[..., 0] = gradient
|
|
|
|
| 193 |
rgb[..., 1] = high_half
|
| 194 |
rgb[..., 2] = low_half
|
| 195 |
else:
|
| 196 |
+
step_1_red = np.clip(norm_img * 3, 0, 1)
|
| 197 |
+
step_2_red = np.clip((norm_img - 0.333) * 3, 0, 1)
|
| 198 |
+
step_3_red = np.clip((norm_img - 0.666) * 3, 0, 1)
|
| 199 |
+
|
| 200 |
+
step_1_cyan = np.clip(norm_img / 0.375, 0, 1)
|
| 201 |
+
step_2_cyan = np.clip((norm_img - 0.375) / 0.5, 0, 1)
|
| 202 |
+
step_3_cyan = np.clip((norm_img - 0.875) / 0.125, 0, 1)
|
| 203 |
+
|
| 204 |
if color_name == "Red Hot":
|
| 205 |
+
rgb[..., 0] = step_1_red
|
| 206 |
+
rgb[..., 1] = step_2_red
|
| 207 |
+
rgb[..., 2] = step_3_red
|
| 208 |
elif color_name == "Cyan Hot":
|
| 209 |
+
rgb[..., 2] = step_1_cyan
|
| 210 |
+
rgb[..., 1] = step_2_cyan
|
| 211 |
+
rgb[..., 0] = step_3_cyan
|
| 212 |
|
| 213 |
elif color_name == "Green (GFP)": rgb[..., 1] = norm_img
|
| 214 |
elif color_name == "Red (RFP)": rgb[..., 0] = norm_img
|
|
|
|
| 625 |
t2i_btn = gr.Button("Generate", variant="primary")
|
| 626 |
with gr.Column(scale=2):
|
| 627 |
# Changed: Image to Gallery
|
| 628 |
+
t2i_gallery_out = gr.Gallery(label="Generated Images", columns=3, height="auto", show_download_button=False, show_share_button=False)
|
| 629 |
with gr.Row(equal_height=True):
|
| 630 |
with gr.Column(scale=2):
|
| 631 |
t2i_color = gr.Dropdown(choices=COLOR_MAPS, value="Green (GFP)", label="Pseudocolor (Adjust after generation)")
|