Update utils.py
Browse files
utils.py
CHANGED
|
@@ -2,6 +2,7 @@ import pydicom
|
|
| 2 |
import numpy as np
|
| 3 |
from PIL import Image
|
| 4 |
import time
|
|
|
|
| 5 |
from datetime import datetime
|
| 6 |
from reportlab.pdfgen import canvas
|
| 7 |
from reportlab.lib.pagesizes import letter
|
|
@@ -20,8 +21,9 @@ def convert_dicom_zip_to_nifti(zip_file):
|
|
| 20 |
"""
|
| 21 |
|
| 22 |
# Step 1: Setup temp directories
|
| 23 |
-
|
| 24 |
-
|
|
|
|
| 25 |
os.makedirs(tmp_dir, exist_ok=True)
|
| 26 |
os.makedirs(nifti_dir, exist_ok=True)
|
| 27 |
|
|
@@ -81,33 +83,33 @@ def convert_dicom_zip_to_nifti(zip_file):
|
|
| 81 |
|
| 82 |
return sequence_images
|
| 83 |
|
| 84 |
-
def load_dicoms(filepaths):
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
|
| 94 |
-
|
| 95 |
-
|
| 96 |
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
|
| 101 |
-
|
| 102 |
-
|
| 103 |
|
| 104 |
-
|
| 105 |
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
|
| 110 |
-
|
| 111 |
|
| 112 |
def generate_pdf(report_text):
|
| 113 |
"""
|
|
|
|
| 2 |
import numpy as np
|
| 3 |
from PIL import Image
|
| 4 |
import time
|
| 5 |
+
import uuid
|
| 6 |
from datetime import datetime
|
| 7 |
from reportlab.pdfgen import canvas
|
| 8 |
from reportlab.lib.pagesizes import letter
|
|
|
|
| 21 |
"""
|
| 22 |
|
| 23 |
# Step 1: Setup temp directories
|
| 24 |
+
unique_id = uuid.uuid4().hex
|
| 25 |
+
tmp_dir = f"/tmp/dicom_{unique_id}"
|
| 26 |
+
nifti_dir = f"/tmp/nifti_{unique_id}"
|
| 27 |
os.makedirs(tmp_dir, exist_ok=True)
|
| 28 |
os.makedirs(nifti_dir, exist_ok=True)
|
| 29 |
|
|
|
|
| 83 |
|
| 84 |
return sequence_images
|
| 85 |
|
| 86 |
+
# def load_dicoms(filepaths):
|
| 87 |
+
# """
|
| 88 |
+
# Accepts a list of DICOM file objects.
|
| 89 |
+
# Returns a list of PIL Images, one per sequence.
|
| 90 |
+
# """
|
| 91 |
|
| 92 |
+
# images=[]
|
| 93 |
+
# for file in filepaths:
|
| 94 |
+
# dicom = pydicom.dcmread(file.name)
|
| 95 |
|
| 96 |
+
# # Extract the pixel array
|
| 97 |
+
# pixel_array = dicom.pixel_array.astype(float)
|
| 98 |
|
| 99 |
+
# # Normalize to 0-255 range
|
| 100 |
+
# pixel_min = pixel_array.min()
|
| 101 |
+
# pixel_max = pixel_array.max()
|
| 102 |
|
| 103 |
+
# if pixel_max - pixel_min == 0:
|
| 104 |
+
# continue #to handle sequences not added
|
| 105 |
|
| 106 |
+
# normalized = (pixel_array - pixel_min) / (pixel_max - pixel_min) * 255
|
| 107 |
|
| 108 |
+
# # Convert to uint8 RGB image
|
| 109 |
+
# image = Image.fromarray(normalized.astype(np.uint8)).convert("RGB")
|
| 110 |
+
# images.append(image)
|
| 111 |
|
| 112 |
+
# return images
|
| 113 |
|
| 114 |
def generate_pdf(report_text):
|
| 115 |
"""
|