Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from PIL import Image, ImageEnhance
|
3 |
import pandas as pd
|
@@ -13,7 +37,7 @@ def zoom_at(img, x, y, zoom):
|
|
13 |
return img.resize((w, h), Image.LANCZOS)
|
14 |
|
15 |
st.set_page_config(page_title="Cell Explorer", layout="wide")
|
16 |
-
st.title("CLL Explorer -
|
17 |
|
18 |
st.markdown("""
|
19 |
### About This Application
|
@@ -31,12 +55,22 @@ if uploaded_files:
|
|
31 |
img_data = uploaded_files[img_index].read()
|
32 |
img = Image.open(io.BytesIO(img_data)).resize((500, 500))
|
33 |
|
34 |
-
|
|
|
|
|
35 |
|
36 |
-
|
37 |
-
|
38 |
|
39 |
-
with
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
st.subheader("Image Controls")
|
41 |
x = st.slider("X Coordinate", 0, 500, 250)
|
42 |
y = st.slider("Y Coordinate", 0, 500, 250)
|
@@ -47,14 +81,14 @@ if uploaded_files:
|
|
47 |
brightness = st.slider("Brightness", 0.0, 5.0, 1.0)
|
48 |
sharpness = st.slider("Sharpness", 0.0, 2.0, 1.0)
|
49 |
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
-
|
53 |
-
img_zoomed = zoom_at(img, x, y, zoom)
|
54 |
-
img_contrast = ImageEnhance.Contrast(img_zoomed).enhance(contrast)
|
55 |
-
img_bright = ImageEnhance.Brightness(img_contrast).enhance(brightness)
|
56 |
-
img_sharp = ImageEnhance.Sharpness(img_bright).enhance(sharpness)
|
57 |
-
st.image(img_sharp, caption="Processed Image", use_column_width=True)
|
58 |
|
59 |
with actions_col:
|
60 |
save_image = st.checkbox("Save Image")
|
@@ -88,3 +122,7 @@ if uploaded_files:
|
|
88 |
os.rename("saved_image_parameters.json", f"saved_image_parameters{file_ext}.json")
|
89 |
os.rename("saved_image_description.txt", f"saved_image_description{file_ext}.txt")
|
90 |
st.success("Files renamed successfully")
|
|
|
|
|
|
|
|
|
|
1 |
+
'''
|
2 |
+
This is the originall CLL Explorer application that allows users to upload, process, and save images.
|
3 |
+
|
4 |
+
The application provides the following functionalities:
|
5 |
+
- Upload microscope images.
|
6 |
+
- Adjust image view with zoom and enhancement controls.
|
7 |
+
- Detect and measure cells automatically.
|
8 |
+
- Save analysis results and annotations.
|
9 |
+
|
10 |
+
The application is divided into the following sections:
|
11 |
+
1. **Upload Images**: Users can upload microscope images in JPG or PNG format.
|
12 |
+
2. **Select Image**: Users can select an image from the uploaded files.
|
13 |
+
3. **Processed Image**: Displays the processed image with zoom and enhancement controls.
|
14 |
+
4. **Image Controls**: Allows users to adjust the image view with sliders for X and Y coordinates, zoom, contrast, brightness, and sharpness.
|
15 |
+
5. **Save Options**: Provides options to save the processed image, image description, and image parameters.
|
16 |
+
|
17 |
+
To run the application:
|
18 |
+
1. Save the script in a Python file (e.g., app.py).
|
19 |
+
2. Run the script using the Streamlit command:
|
20 |
+
```bash
|
21 |
+
streamlit run app.py
|
22 |
+
```
|
23 |
+
'''
|
24 |
+
|
25 |
import streamlit as st
|
26 |
from PIL import Image, ImageEnhance
|
27 |
import pandas as pd
|
|
|
37 |
return img.resize((w, h), Image.LANCZOS)
|
38 |
|
39 |
st.set_page_config(page_title="Cell Explorer", layout="wide")
|
40 |
+
st.title("CLL Explorer - Annotate: Upload, Process, and Save Images")
|
41 |
|
42 |
st.markdown("""
|
43 |
### About This Application
|
|
|
55 |
img_data = uploaded_files[img_index].read()
|
56 |
img = Image.open(io.BytesIO(img_data)).resize((500, 500))
|
57 |
|
58 |
+
# Display the original image first
|
59 |
+
st.subheader("Original Image")
|
60 |
+
st.image(img, caption="Original Image", use_column_width=True)
|
61 |
|
62 |
+
# Arrange layout for processed image and controls
|
63 |
+
processed_col, controls_col = st.columns([3, 2])
|
64 |
|
65 |
+
with processed_col:
|
66 |
+
st.subheader("Processed Image")
|
67 |
+
img_zoomed = zoom_at(img, 250, 250, 5)
|
68 |
+
img_contrast = ImageEnhance.Contrast(img_zoomed).enhance(1.0)
|
69 |
+
img_bright = ImageEnhance.Brightness(img_contrast).enhance(1.0)
|
70 |
+
img_sharp = ImageEnhance.Sharpness(img_bright).enhance(1.0)
|
71 |
+
st.image(img_sharp, use_column_width=True)
|
72 |
+
|
73 |
+
with controls_col:
|
74 |
st.subheader("Image Controls")
|
75 |
x = st.slider("X Coordinate", 0, 500, 250)
|
76 |
y = st.slider("Y Coordinate", 0, 500, 250)
|
|
|
81 |
brightness = st.slider("Brightness", 0.0, 5.0, 1.0)
|
82 |
sharpness = st.slider("Sharpness", 0.0, 2.0, 1.0)
|
83 |
|
84 |
+
if st.button("Apply Adjustments"):
|
85 |
+
img_zoomed = zoom_at(img, x, y, zoom)
|
86 |
+
img_contrast = ImageEnhance.Contrast(img_zoomed).enhance(contrast)
|
87 |
+
img_bright = ImageEnhance.Brightness(img_contrast).enhance(brightness)
|
88 |
+
img_sharp = ImageEnhance.Sharpness(img_bright).enhance(sharpness)
|
89 |
+
st.image(img_sharp, use_column_width=True, caption="Processed Image")
|
90 |
|
91 |
+
actions_col, save_col = st.columns([2, 3])
|
|
|
|
|
|
|
|
|
|
|
92 |
|
93 |
with actions_col:
|
94 |
save_image = st.checkbox("Save Image")
|
|
|
122 |
os.rename("saved_image_parameters.json", f"saved_image_parameters{file_ext}.json")
|
123 |
os.rename("saved_image_description.txt", f"saved_image_description{file_ext}.txt")
|
124 |
st.success("Files renamed successfully")
|
125 |
+
|
126 |
+
# Display Original Image Below Processed Image
|
127 |
+
st.markdown("### Original Image")
|
128 |
+
st.image(img, use_column_width=True)
|