wangjin2000 commited on
Commit
abb03da
·
verified ·
1 Parent(s): 55ade3c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -3
app.py CHANGED
@@ -141,7 +141,7 @@ def read_and_preprocess_dicom(file_path: str):
141
  """
142
  Function to read and preprocess DICOM files
143
  :param file_path: Path to the DICOM file
144
- :return: Image data (in PIL format) and metadata (in pandas DataFrame format)
145
  """
146
  try:
147
  # Read the DICOM file
@@ -159,8 +159,10 @@ def read_and_preprocess_dicom(file_path: str):
159
  if pixel_array.dtype != np.uint8:
160
  pixel_array = ((pixel_array - np.min(pixel_array)) / (np.max(pixel_array) - np.min(pixel_array)) * 255).astype(
161
  np.uint8)
162
- image = Image.fromarray(pixel_array)
163
-
 
 
164
  # Collect metadata in dictionary format and convert to DataFrame
165
  metadata_dict = {elem.name: str(elem.value) for elem in dicom_data.iterall() if elem.name != 'Pixel Data'}
166
  df_metadata = pl.DataFrame({
 
141
  """
142
  Function to read and preprocess DICOM files
143
  :param file_path: Path to the DICOM file
144
+ :return: Image data (in CV2 format) and metadata (in pandas DataFrame format)
145
  """
146
  try:
147
  # Read the DICOM file
 
159
  if pixel_array.dtype != np.uint8:
160
  pixel_array = ((pixel_array - np.min(pixel_array)) / (np.max(pixel_array) - np.min(pixel_array)) * 255).astype(
161
  np.uint8)
162
+ image_pil = Image.fromarray(pixel_array)
163
+ #convert to cv2 format
164
+ image = numpy.array(image_pil)[:, :, ::-1].copy()
165
+
166
  # Collect metadata in dictionary format and convert to DataFrame
167
  metadata_dict = {elem.name: str(elem.value) for elem in dicom_data.iterall() if elem.name != 'Pixel Data'}
168
  df_metadata = pl.DataFrame({