File size: 4,489 Bytes
e83143a
 
 
 
66b5fa9
 
e83143a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66b5fa9
 
 
 
 
 
 
 
 
 
 
c141b0d
8895532
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a1e7983
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import streamlit as st
import mahotas as mh
import pandas as pd
import plotly.express as px
import urllib.request
from skimage import io

# 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
    if selected_condition == "Depression":
        image_url = "https://i.imgur.com/kPQoD8C.jpg"
    elif selected_condition == "Anxiety":
        image_url = "https://i.imgur.com/ZWyKjJN.jpg"
    elif selected_condition == "Diabetes":
        image_url = "https://i.imgur.com/1gOEMO5.jpg"
    elif selected_condition == "Hypertension":
        image_url = "https://i.imgur.com/BoSUwio.jpg"
    elif selected_condition == "Asthma":
        image_url = "https://i.imgur.com/BLKjzJF.jpg"
    elif selected_condition == "Cancer":
        image_url = "https://i.imgur.com/nq3vV8.jpg"
    elif selected_condition == "Arthritis":
        image_url = "https://i.imgur.com/ffzd6Fo.jpg"
    elif selected_condition == "Heart disease":
        image_url = "https://i.imgur.com/1I7axhd.jpg"
    elif selected_condition == "Obesity":
        image_url = "https://i.imgur.com/nZ1EjJr.jpg"
    else:
        image_url = "https://i.imgur.com/RUBZOWF.jpg"
    
    image = io.imread(image_url)
    
    # 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)

    st.markdown("""
# Alternate Image Links Per Condition:
Depression: https://www.pexels.com/photo/woman-sitting-on-grass-field-while-holding-her-head-7127866/
Anxiety: https://www.pexels.com/photo/woman-sitting-on-rock-and-looking-at-the-ocean-7119798/
Diabetes: https://www.pexels.com/photo/man-taking-blood-sugar-test-4050305/
Hypertension: https://www.pexels.com/photo/woman-measuring-blood-pressure-with-sphygmomanometer-5691686/
Asthma: https://www.pexels.com/photo/woman-having-asthma-attack-in-park-7127511/
Cancer: https://www.pexels.com/photo/close-up-of-pink-ribbon-on-cancer-awareness-banner-4219366/
Arthritis: https://www.pexels.com/photo/man-with-back-pain-lying-on-bed-4050323/
Heart disease: https://www.pexels.com/photo/woman-touching-chest-during-chest-pain-7127487/
Obesity: https://www.pexels.com/photo/woman-in-black-pants-lying-on-bed-7127516/
    """)