import streamlit as st import pydicom import matplotlib.pyplot as plt # Streamlit app title st.title("DICOM Image Viewer") # Upload a DICOM file uploaded_file = st.file_uploader("Upload a DICOM file", type=["dcm"]) if uploaded_file is not None: try: # Read the uploaded DICOM file dicom_data = pydicom.dcmread(uploaded_file) # Display the DICOM image plt.imshow(dicom_data.pixel_array, cmap=plt.cm.bone) plt.axis("off") plt.title("DICOM Image") plt.tight_layout() # Show the image in the Streamlit app st.pyplot(plt) except Exception as e: st.error(f"Error: {str(e)}") st.write("Upload a DICOM file to view the image.")