VizLib-Mahotas / app.py
awacke1's picture
Create app.py
e83143a
raw
history blame
2.67 kB
import streamlit as st
import mahotas as mh
import pandas as pd
import plotly.express as px
# Define a list of medical conditions
conditions = [
{"name": "Depression", "test_for": "Patient Health Questionnaire-9 (PHQ-9)"},
{"name": "Anxiety", "test_for": "Generalized Anxiety Disorder-7 (GAD-7)"},
{"name": "Diabetes", "test_for": "Hemoglobin A1C test"},
{"name": "Hypertension", "test_for": "Blood pressure measurement"},
{"name": "Asthma", "test_for": "Pulmonary function test"},
{"name": "Cancer", "test_for": "Biopsy or imaging tests (e.g., CT scan, MRI)"},
{"name": "Arthritis", "test_for": "X-ray, MRI, or ultrasound"},
{"name": "Heart disease", "test_for": "Electrocardiogram (ECG)"},
{"name": "Obesity", "test_for": "Body mass index (BMI)"},
{"name": "Substance use disorder", "test_for": "Substance Abuse Subtle Screening Inventory (SASSI)"}
]
# Define a function to process images using Mahotas
def process_image(image):
# Convert the image to grayscale
grayscale_image = mh.colors.rgb2gray(image)
# Apply a Gaussian filter to the image to reduce noise
filtered_image = mh.gaussian_filter(grayscale_image, 4)
# Threshold the image to create a binary image
binary_image = filtered_image > mh.otsu(filtered_image)
# Compute the connected components in the binary image
labels, num_labels = mh.label(binary_image)
# Compute the size of each connected component
sizes = mh.labeled.labeled_size(labels)
# Sort the sizes in descending order
sorted_sizes = sorted(sizes, reverse=True)
# Return the top 10 sizes
return sorted_sizes[:10]
# Define the Streamlit app
def app():
# Add a title to the app
st.title("Mahotas Demo")
# Add a sidebar to the app
st.sidebar.title("Medical Conditions")
selected_condition = st.sidebar.selectbox("Select a condition", [c["name"] for c in conditions])
# Get the selected condition
condition = next(c for c in conditions if c["name"] == selected_condition)
# Display the selected condition
st.header(condition["name"])
st.write("Test for:", condition["test_for"])
# Load an example medical image
image = mh.imread("https://i.imgur.com/kPQoD8C.jpg")
# Process the image using Mahotas
sizes = process_image(image)
# Display the top 10 connected component sizes
df = pd.DataFrame({"Size": sizes})
st.write(df)
# Create a sunburst chart using Plotly
fig = px.sunburst(
df,
path=["Size"],
values="Size",
color="Size",
color_continuous_scale="blues"
)
st.plotly_chart(fig)
if __name__ == "__main__":
app()