Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -28,6 +28,36 @@ streamlit run cell_exp_past.py
|
|
28 |
associated files.
|
29 |
'''
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
import streamlit as st
|
32 |
from PIL import Image, ImageEnhance
|
33 |
import pandas as pd
|
@@ -45,7 +75,7 @@ def zoom_at(img, x, y, zoom):
|
|
45 |
x + w / zoom2, y + h / zoom2))
|
46 |
return img.resize((w, h), Image.LANCZOS)
|
47 |
|
48 |
-
st.title("
|
49 |
|
50 |
uploaded_files = st.file_uploader("Upload Images", accept_multiple_files=True, type="jpg")
|
51 |
|
@@ -53,7 +83,7 @@ if uploaded_files:
|
|
53 |
img_index = st.selectbox("Select Image", range(len(uploaded_files)))
|
54 |
x = st.slider("X Coordinate", 0, 500, 205)
|
55 |
y = st.slider("Y Coordinate", 0, 500, 250)
|
56 |
-
zoom = st.slider("Zoom", 1
|
57 |
contrast = st.slider("Contrast", 0.0, 5.0, 1.0)
|
58 |
brightness = st.slider("Brightness", 0.0, 5.0, 1.0)
|
59 |
sharpness = st.slider("Sharpness", 0.0, 2.0, 1.0)
|
@@ -127,11 +157,30 @@ if uploaded_files:
|
|
127 |
st.success("Files renamed successfully")
|
128 |
|
129 |
if st.button("Export to ZIP"):
|
|
|
|
|
|
|
|
|
130 |
with tempfile.NamedTemporaryFile(delete=False, suffix='.zip') as zipf:
|
131 |
with zipfile.ZipFile(zipf.name, 'w') as z:
|
132 |
-
if
|
133 |
z.write(desc_file, os.path.basename(desc_file))
|
134 |
-
|
|
|
|
|
|
|
135 |
z.write(params_file, os.path.basename(params_file))
|
136 |
-
|
137 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
associated files.
|
29 |
'''
|
30 |
|
31 |
+
'''
|
32 |
+
an image processing tool that allows users to upload microscope images,
|
33 |
+
adjust the view with zoom and enhancement controls, and save the processed
|
34 |
+
image along with annotations. The tool uses OpenCV for image processing and
|
35 |
+
PIL for image enhancements. The processed image can be saved locally or
|
36 |
+
exported as a zip file containing the processed image, description, and
|
37 |
+
parameters. The tool also provides options to rename the processed image and
|
38 |
+
associated files.
|
39 |
+
|
40 |
+
The tool consists of the following components:
|
41 |
+
1. File Uploader: Allows users to upload microscope images in JPG or PNG format.
|
42 |
+
2. Image Controls: Provides sliders to adjust the zoom, contrast, brightness, and sharpness of the image.
|
43 |
+
3. Processed Image Display: Displays the processed image after applying the adjustments.
|
44 |
+
4. Original Image Display: Displays the original image uploaded by the user.
|
45 |
+
5. Save and Export Options: Allows users to add annotations, prepare a zip file for download, save the processed image locally, and rename the processed image and associated files.
|
46 |
+
|
47 |
+
To run the tool:
|
48 |
+
1. Save the script as `cell_exp_past.py`.
|
49 |
+
2. Run the script in a Python environment.
|
50 |
+
```python
|
51 |
+
streamlit run cell_exp_past.py
|
52 |
+
```
|
53 |
+
3. Open the provided local URL in a web browser.
|
54 |
+
4. Upload microscope images and adjust the image view.
|
55 |
+
5. Apply adjustments and save the processed image with annotations.
|
56 |
+
6. Download the processed image and annotations as a zip file.
|
57 |
+
7. Save the processed image locally or rename the processed image and
|
58 |
+
associated files.
|
59 |
+
'''
|
60 |
+
|
61 |
import streamlit as st
|
62 |
from PIL import Image, ImageEnhance
|
63 |
import pandas as pd
|
|
|
75 |
x + w / zoom2, y + h / zoom2))
|
76 |
return img.resize((w, h), Image.LANCZOS)
|
77 |
|
78 |
+
st.title("CLL Image Processing Tool")
|
79 |
|
80 |
uploaded_files = st.file_uploader("Upload Images", accept_multiple_files=True, type="jpg")
|
81 |
|
|
|
83 |
img_index = st.selectbox("Select Image", range(len(uploaded_files)))
|
84 |
x = st.slider("X Coordinate", 0, 500, 205)
|
85 |
y = st.slider("Y Coordinate", 0, 500, 250)
|
86 |
+
zoom = st.slider("Zoom", 1, 10, 0.5)
|
87 |
contrast = st.slider("Contrast", 0.0, 5.0, 1.0)
|
88 |
brightness = st.slider("Brightness", 0.0, 5.0, 1.0)
|
89 |
sharpness = st.slider("Sharpness", 0.0, 2.0, 1.0)
|
|
|
157 |
st.success("Files renamed successfully")
|
158 |
|
159 |
if st.button("Export to ZIP"):
|
160 |
+
desc_file = st.session_state.get('desc_file', None)
|
161 |
+
params_file = st.session_state.get('params_file', None)
|
162 |
+
processed_image_path = st.session_state.get('processed_image_path', None)
|
163 |
+
|
164 |
with tempfile.NamedTemporaryFile(delete=False, suffix='.zip') as zipf:
|
165 |
with zipfile.ZipFile(zipf.name, 'w') as z:
|
166 |
+
if desc_file and os.path.exists(desc_file):
|
167 |
z.write(desc_file, os.path.basename(desc_file))
|
168 |
+
else:
|
169 |
+
st.warning("Description file not found and was not added to the ZIP.")
|
170 |
+
|
171 |
+
if params_file and os.path.exists(params_file):
|
172 |
z.write(params_file, os.path.basename(params_file))
|
173 |
+
else:
|
174 |
+
st.warning("Parameters file not found and was not added to the ZIP.")
|
175 |
+
|
176 |
+
if processed_image_path and os.path.exists(processed_image_path):
|
177 |
+
z.write(processed_image_path, os.path.basename(processed_image_path))
|
178 |
+
else:
|
179 |
+
st.warning("Processed image not found and was not added to the ZIP.")
|
180 |
+
|
181 |
+
# Check if the ZIP file has any content
|
182 |
+
if os.path.getsize(zipf.name) > 0:
|
183 |
+
with open(zipf.name, 'rb') as f:
|
184 |
+
st.download_button("Download ZIP", f, "annotations.zip")
|
185 |
+
else:
|
186 |
+
st.error("No files were added to the ZIP. Please ensure files are saved before exporting.")
|