def __pixels_to_image3d_md(self, datasets): """ :param datasets: :return: """ SeriesInstanceUID = datasets[0].SeriesInstanceUID dir = Config.get("db", 'dicom_save_dir') + str(SeriesInstanceUID) vol, tags = cio.read_dicom_series(dir) print vol shutil.rmtree(dir) return vol
def __pixels_to_image3d_md(self, datasets): """ :param datasets: :return: """ SeriesInstanceUID = datasets[0].SeriesInstanceUID dir = Config.get("db", 'dicom_save_dir') + str(SeriesInstanceUID) """ dir = r'/home/uii/PKU_Pro_Final/cmove_data/1.2.840.113564.143313591524.3512.636758772708415433.34' """ vol, tags = cio.read_dicom_series(dir) print vol shutil.rmtree(dir) return vol
def __pixels_to_image3d(self, datasets): """ transform the origin pixels value to numpy and reshape to three dimensions :param datasets: dicom files :return:image3D volume """ # self.pixels = np.array(self.pixels) # self.pixels = np.frombuffer(self.pixels, dtype=self.__get_pixels_data_type(datasets[0]), count=-1, offset=0) # module = self.__check_modality(datasets) # self.pixels = self.pixels * module['RescaleSlope'] + module['RescaleIntercept'] # self.pixels = np.reshape(self.pixels, # (len(self.instance_pixels_position), datasets[0].Rows, datasets[0].Columns)) # im = md.Image3d() # # # set the origin of Image3D Volume # im.from_numpy(self.pixels, np.short) # origin = self.instance_pixels_position[0][2] # im.set_origin(origin) # # # set the pixel spacing of Image3D Volume # x_spacing = datasets[0].PixelSpacing[0] # y_spacing = datasets[0].PixelSpacing[1] # z_spacing = lina.norm(np.array(self.instance_pixels_position[-1][2]) # - np.array(self.instance_pixels_position[0][2]))/(len(self.instance_pixels_position)-1) # im.set_spacing([x_spacing, y_spacing, z_spacing]) # # # set the axes of Image3D Volume # orientation = datasets[0].ImageOrientationPatient # axis_x = np.array([orientation[0], orientation[1], orientation[2]], np.float32) # axis_y = np.array([orientation[3], orientation[4], orientation[5]], np.float32) # axis_z = np.array(self.instance_pixels_position[1][2])-np.array(self.instance_pixels_position[0][2], np.float32) # axis_z = axis_z/(lina.norm(axis_z)) # axes = [axis_x, axis_y, axis_z] # axes = np.reshape(axes, (3, 3)) # im.set_axes(axes) SeriesInstanceUID = datasets[0].SeriesInstanceUID dir = Config.get("db", 'dicom_save_dir') + str(SeriesInstanceUID) # dir = r'/home/lyw/rxl5/pyproject/PKU/dcms/1_test' vol, tags = cio.read_dicom_series(dir) print vol shutil.rmtree(dir) return vol
def build(self, series_path): """ dicom to volume and upload volume to DB :return:volume file path """ vol, tags = read_dicom_series(series_path) seriesuid = tags['0020|000e'] volume_name = seriesuid + '.nii.gz' # 保存文件到本地 if os.path.exists(file_path_ferry.volumePath): pass else: os.mkdir(file_path_ferry.volumePath) volfilepath = os.path.join(file_path_ferry.volumePath, volume_name) if not write_image(vol, volfilepath): pass return volfilepath, seriesuid
img_file = os.path.join(self.img_folder, item['image_uid']) + '.jpg' im.save(img_file) output_buffer = StringIO() im.save(output_buffer, 'JPEG') binary_data = output_buffer.getvalue() base64_data = base64.b64encode(binary_data) base64img_dic[item['image_uid']] = base64_data return base64img_dic if __name__ == '__main__': slice_info = [{ 'instance_num': 634, 'best_instance_num': 634, 'voxel_slice_num': 75, 'image_uid': '1.2.840.113704.1.111.1888.1508053946.10640', 'rectangle_patient': (12, 25, 34, 65), 'rectangle_pixel': (15, 24, 65, 87), 'probability': 1, 'rib_class': 1, 'rib_location': 1, 'min_voxel': (1, 2, 3), 'max_voxel': (4, 5, 6) }] images, tag = cio.read_dicom_series( r'/home/lyw/rxl5/1.2.840.113704.1.111.12164.1508053864.7/') cutter = ImgCutter(slice_info, images) a = cutter.handle()