diff --git a/DicomProcessor.py b/DicomProcessor.py index 44fc729..1ee07fd 100644 --- a/DicomProcessor.py +++ b/DicomProcessor.py @@ -14,7 +14,7 @@ self.args = args self.dicom_dir = dicom_dir self.dicom_file_list = glob.glob(os.path.join(dicom_dir, '*')) - self.dicom_file_list = sorted(self.dicom_file_list, key=lambda x: float(pydicom.read_file(x).SliceLocation), reverse=True) + self.dicom_file_list = sorted(self.dicom_file_list, key=lambda x: float(pydicom.read_file(x).SliceLocation), reverse=False) self.dicom_size = len(self.dicom_file_list) if self.dicom_size == 0: @@ -79,10 +79,10 @@ return LPS def load_initial_CT(self): - CT_img = pydicom.read_file(self.dicom_file_list[0]) - CT_img = CT_img.pixel_array + CT_data = pydicom.read_file(self.dicom_file_list[0]) + CT_row = CT_data.pixel_array + CT_data.RescaleIntercept - return self.row2uint8(CT_img) + return self.row2uint8(CT_row) def row2uint8(self, CT_row, delete_0s=False): if delete_0s: @@ -96,7 +96,7 @@ CT_img[window_max < CT_img] = window_max CT_img -= np.mean(CT_img) - CT_img = CT_img / (np.max(np.abs(CT_img)) + 1e-5) * 128.0 + CT_img = CT_img / (np.max(np.abs(CT_img)) + 1e-5) * 256.0 CT_img -= np.mean(CT_img) CT_img = np.clip(CT_img, 0, 255).astype(np.uint8) CT_img = cv2.cvtColor(CT_img, cv2.COLOR_GRAY2BGR) @@ -108,7 +108,8 @@ def get_CT_by_index(self, dicom_index): # print(self.dicom_file_list[dicom_index]) - CT_row = pydicom.read_file(self.dicom_file_list[dicom_index]).pixel_array + CT_data = pydicom.read_file(self.dicom_file_list[dicom_index]) + CT_row = CT_data.pixel_array + CT_data.RescaleIntercept return self.row2uint8(CT_row) @@ -116,7 +117,7 @@ return self.dicom_size - dicom_index - 1 def make_distorted_dicom(self, ijk_eso_centers, img_eso_radius): - pad_eso_centers = self.liner_pad_list(ijk_eso_centers) + pad_eso_centers = self.linear_pad_list(ijk_eso_centers) os.makedirs(self.args.out_dicom_dir, exist_ok=True) if (self.dicom_col_num % 2 != 0) and (self.dicom_row_num % 2 != 0): print('It may not be able to get correct dicom image. In detail, please ask to Yukiya') @@ -128,7 +129,6 @@ [half_col_num, 0], [0, 0], [0, half_row_num], [0, self.dicom_row_num]], dtype=np.float32) for dicom_index, eso_center in enumerate(pad_eso_centers): - print("a") file_name = os.path.basename(self.dicom_file_list[dicom_index]) new_dicom_path = os.path.join(self.args.out_dicom_dir, file_name) if eso_center is None: @@ -163,8 +163,7 @@ ds.PixelData = out.tobytes() ds.save_as(new_dicom_path) - - def liner_pad_list(self, ijk_eso_centers): + def linear_pad_list(self, ijk_eso_centers): pad_center_list = [] Is_first = True prev_index = 0