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
|
@@ -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, 10, 5)
|
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)
|
@@ -70,7 +100,7 @@ if uploaded_files:
|
|
70 |
img_sharp.save("image-processed.jpg")
|
71 |
st.success("Image saved as image-processed.jpg")
|
72 |
|
73 |
-
st.image(img_sharp, caption="Processed Image",
|
74 |
|
75 |
description = st.text_area("Describe the image", "")
|
76 |
if st.button("Save Description"):
|
@@ -95,7 +125,10 @@ if uploaded_files:
|
|
95 |
|
96 |
if st.button("Rename Files"):
|
97 |
file_ext = str(np.random.randint(100))
|
98 |
-
|
|
|
|
|
|
|
99 |
os.rename("saved_image_parameters.json", f"saved_image_parameters{file_ext}.json")
|
100 |
os.rename("saved_image_description.txt", f"saved_image_description{file_ext}.txt")
|
101 |
st.success("Files renamed successfully")
|
@@ -109,3 +142,4 @@ if uploaded_files:
|
|
109 |
z.write(params_file, os.path.basename(params_file))
|
110 |
with open(zipf.name, 'rb') as f:
|
111 |
st.download_button("Download ZIP", f, "annotations.zip")
|
|
|
|
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
|
|
|
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)
|
|
|
100 |
img_sharp.save("image-processed.jpg")
|
101 |
st.success("Image saved as image-processed.jpg")
|
102 |
|
103 |
+
st.image(img_sharp, caption="Processed Image", use_container_width=True)
|
104 |
|
105 |
description = st.text_area("Describe the image", "")
|
106 |
if st.button("Save Description"):
|
|
|
125 |
|
126 |
if st.button("Rename Files"):
|
127 |
file_ext = str(np.random.randint(100))
|
128 |
+
try:
|
129 |
+
os.rename("image-processed.jpg", f"img_processed{file_ext}.jpg")
|
130 |
+
except FileNotFoundError:
|
131 |
+
st.error("image-processed.jpg not found.")
|
132 |
os.rename("saved_image_parameters.json", f"saved_image_parameters{file_ext}.json")
|
133 |
os.rename("saved_image_description.txt", f"saved_image_description{file_ext}.txt")
|
134 |
st.success("Files renamed successfully")
|
|
|
142 |
z.write(params_file, os.path.basename(params_file))
|
143 |
with open(zipf.name, 'rb') as f:
|
144 |
st.download_button("Download ZIP", f, "annotations.zip")
|
145 |
+
|