Open yellowblue6 opened 16 hours ago
Yes, you can extract the pixel data or image from the DICOM file and then encoding it in base64 format. For example,
# Function to convert DICOM to base64
def dicom_to_base64(dicom_file_path):
dicom = pydicom.dcmread(dicom_file_path)
pixel_array = dicom.pixel_array
image = Image.fromarray(pixel_array)
# Convert the image to PNG and save it into a BytesIO object
buffered = BytesIO()
image.save(buffered, format="PNG")
# Get the binary content and encode it into base64
img_base64 = base64.b64encode(buffered.getvalue()).decode('utf-8')
return img_base64
hello Author, thanks for the work. can one use dicom(.dcm) images for training instead of jpg ?