Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,63 +4,82 @@ import pandas as pd
|
|
| 4 |
import numpy as np
|
| 5 |
import io
|
| 6 |
import os
|
|
|
|
| 7 |
|
| 8 |
def zoom_at(img, x, y, zoom):
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
st.
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
import numpy as np
|
| 5 |
import io
|
| 6 |
import os
|
| 7 |
+
from pathlib import Path
|
| 8 |
|
| 9 |
def zoom_at(img, x, y, zoom):
|
| 10 |
+
# ...existing code...
|
| 11 |
+
|
| 12 |
+
# App title and description
|
| 13 |
+
st.set_page_config(page_title="Cell Explorer", layout="wide")
|
| 14 |
+
st.title("CLL Explorer: Annotation Tool")
|
| 15 |
+
|
| 16 |
+
st.markdown("""
|
| 17 |
+
### About this Application
|
| 18 |
+
This tool helps researchers analyze microscope images of blood cells for malaria detection:
|
| 19 |
+
- Upload microscope images
|
| 20 |
+
- Adjust image view with zoom and enhancement controls
|
| 21 |
+
- Detect and measure cells automatically
|
| 22 |
+
- Save analysis results and annotations
|
| 23 |
+
|
| 24 |
+
**Note**: Cell measurements are in micrometers (µm)
|
| 25 |
+
""")
|
| 26 |
+
|
| 27 |
+
# Create tabs for different functions
|
| 28 |
+
tab1, tab2, tab3 = st.tabs(["Image Analysis", "Detection Results", "Settings"])
|
| 29 |
+
|
| 30 |
+
with tab1:
|
| 31 |
+
col1, col2 = st.columns([2,1])
|
| 32 |
+
|
| 33 |
+
with col1:
|
| 34 |
+
uploaded_files = st.file_uploader("Upload Images", accept_multiple_files=True, type=["jpg", "png"])
|
| 35 |
+
|
| 36 |
+
if uploaded_files:
|
| 37 |
+
img_index = st.selectbox("Select Image", range(len(uploaded_files)))
|
| 38 |
+
img_data = uploaded_files[img_index].read()
|
| 39 |
+
img = Image.open(io.BytesIO(img_data)).resize((800, 800))
|
| 40 |
+
|
| 41 |
+
st.image(img, caption="Original Image", use_column_width=True)
|
| 42 |
+
|
| 43 |
+
with col2:
|
| 44 |
+
if uploaded_files:
|
| 45 |
+
st.subheader("Image Controls")
|
| 46 |
+
x = st.slider("X Position", 0, 800, 400)
|
| 47 |
+
y = st.slider("Y Position", 0, 800, 400)
|
| 48 |
+
zoom = st.slider("Zoom Level", 1, 10, 5)
|
| 49 |
+
|
| 50 |
+
with st.expander("Enhancement Settings"):
|
| 51 |
+
contrast = st.slider("Contrast", 0.0, 5.0, 1.0)
|
| 52 |
+
brightness = st.slider("Brightness", 0.0, 5.0, 1.0)
|
| 53 |
+
sharpness = st.slider("Sharpness", 0.0, 2.0, 1.0)
|
| 54 |
+
|
| 55 |
+
img_zoomed = zoom_at(img, x, y, zoom)
|
| 56 |
+
img_processed = ImageEnhance.Contrast(img_zoomed).enhance(contrast)
|
| 57 |
+
img_processed = ImageEnhance.Brightness(img_processed).enhance(brightness)
|
| 58 |
+
img_processed = ImageEnhance.Sharpness(img_processed).enhance(sharpness)
|
| 59 |
+
|
| 60 |
+
st.image(img_processed, caption="Processed View", use_column_width=True)
|
| 61 |
+
|
| 62 |
+
with tab2:
|
| 63 |
+
if uploaded_files:
|
| 64 |
+
st.subheader("Cell Detection Results")
|
| 65 |
+
# Add your existing cell detection code here
|
| 66 |
+
|
| 67 |
+
col1, col2 = st.columns(2)
|
| 68 |
+
with col1:
|
| 69 |
+
description = st.text_area("Analysis Notes", "")
|
| 70 |
+
with col2:
|
| 71 |
+
if st.button("Save Analysis"):
|
| 72 |
+
timestamp = pd.Timestamp.now().strftime("%Y%m%d_%H%M%S")
|
| 73 |
+
save_dir = Path("analysis_results") / timestamp
|
| 74 |
+
save_dir.mkdir(parents=True, exist_ok=True)
|
| 75 |
+
|
| 76 |
+
img_processed.save(save_dir / "processed_image.jpg")
|
| 77 |
+
with open(save_dir / "analysis_notes.txt", "w") as f:
|
| 78 |
+
f.write(description)
|
| 79 |
+
st.success(f"Analysis saved to {save_dir}")
|
| 80 |
+
|
| 81 |
+
with tab3:
|
| 82 |
+
st.subheader("Application Settings")
|
| 83 |
+
st.checkbox("Enable Auto-Detection", value=True)
|
| 84 |
+
st.selectbox("Measurement Unit", ["Micrometers", "Pixels"])
|
| 85 |
+
st.number_input("Detection Confidence Threshold", 0.0, 1.0, 0.5)
|