def OpenBitmapFiles(self, bmp_data, rec_data): name = rec_data[0] orientation = rec_data[1] sp_x = float(rec_data[2]) sp_y = float(rec_data[3]) sp_z = float(rec_data[4]) interval = int(rec_data[5]) interval += 1 filelist = bmp_data.GetOnlyBitmapPath()[::interval] bits = bmp_data.GetFirstPixelSize() sx, sy = size = bmp_data.GetFirstBitmapSize() n_slices = len(filelist) resolution_percentage = utils.calculate_resizing_tofitmemory( int(sx), int(sy), n_slices, bits / 8) zspacing = sp_z * interval xyspacing = (sp_y, sp_x) if resolution_percentage < 1.0: re_dialog = dialog.ResizeImageDialog() re_dialog.SetValue(int(resolution_percentage * 100)) re_dialog_value = re_dialog.ShowModal() re_dialog.Close() if re_dialog_value == wx.ID_OK: percentage = re_dialog.GetValue() resolution_percentage = percentage / 100.0 else: return xyspacing = xyspacing[0] / resolution_percentage, xyspacing[ 1] / resolution_percentage self.matrix, scalar_range, self.filename = image_utils.bitmap2memmap( filelist, size, orientation, (sp_z, sp_y, sp_x), resolution_percentage) self.Slice = sl.Slice() self.Slice.matrix = self.matrix self.Slice.matrix_filename = self.filename if orientation == 'AXIAL': self.Slice.spacing = xyspacing[0], xyspacing[1], zspacing elif orientation == 'CORONAL': self.Slice.spacing = xyspacing[0], zspacing, xyspacing[1] elif orientation == 'SAGITTAL': self.Slice.spacing = zspacing, xyspacing[1], xyspacing[0] self.Slice.window_level = float(self.matrix.max() / 4) self.Slice.window_width = float(self.matrix.max()) scalar_range = int(self.matrix.min()), int(self.matrix.max()) Publisher.sendMessage('Update threshold limits list', threshold_range=scalar_range) return self.matrix, self.filename #, dicom
def OpenBitmapFiles(self, bmp_data, rec_data): name = rec_data[0] orientation = rec_data[1] sp_x = float(rec_data[2]) sp_y = float(rec_data[3]) sp_z = float(rec_data[4]) interval = int(rec_data[5]) interval += 1 filelist = bmp_data.GetOnlyBitmapPath()[::interval] bits = bmp_data.GetFirstPixelSize() sx, sy = size = bmp_data.GetFirstBitmapSize() n_slices = len(filelist) resolution_percentage = utils.calculate_resizing_tofitmemory(int(sx), int(sy), n_slices, bits/8) zspacing = sp_z * interval xyspacing = (sp_y, sp_x) if resolution_percentage < 1.0: re_dialog = dialog.ResizeImageDialog() re_dialog.SetValue(int(resolution_percentage*100)) re_dialog_value = re_dialog.ShowModal() re_dialog.Close() if re_dialog_value == wx.ID_OK: percentage = re_dialog.GetValue() resolution_percentage = percentage / 100.0 else: return xyspacing = xyspacing[0] / resolution_percentage, xyspacing[1] / resolution_percentage self.matrix, scalar_range, self.filename = image_utils.bitmap2memmap(filelist, size, orientation, (sp_z, sp_y, sp_x),resolution_percentage) self.Slice = sl.Slice() self.Slice.matrix = self.matrix self.Slice.matrix_filename = self.filename if orientation == 'AXIAL': self.Slice.spacing = xyspacing[0], xyspacing[1], zspacing elif orientation == 'CORONAL': self.Slice.spacing = xyspacing[0], zspacing, xyspacing[1] elif orientation == 'SAGITTAL': self.Slice.spacing = zspacing, xyspacing[1], xyspacing[0] self.Slice.window_level = float(self.matrix.max()/4) self.Slice.window_width = float(self.matrix.max()) scalar_range = int(self.matrix.min()), int(self.matrix.max()) Publisher.sendMessage('Update threshold limits list', threshold_range=scalar_range) return self.matrix, self.filename#, dicom
def OpenDicomGroup(self, dicom_group, interval, file_range, gui=True): # Retrieve general DICOM headers dicom = dicom_group.GetDicomSample() # Create imagedata interval += 1 filelist = dicom_group.GetFilenameList()[::interval] if not filelist: utils.debug("Not used the IPPSorter") filelist = [ i.image.file for i in dicom_group.GetHandSortedList()[::interval] ] if file_range is not None and file_range[ 0] is not None and file_range[1] > file_range[0]: filelist = filelist[file_range[0]:file_range[1] + 1] zspacing = dicom_group.zspacing * interval size = dicom.image.size bits = dicom.image.bits_allocad sop_class_uid = dicom.acquisition.sop_class_uid xyspacing = dicom.image.spacing orientation = dicom.image.orientation_label wl = float(dicom.image.level) ww = float(dicom.image.window) if sop_class_uid == '1.2.840.10008.5.1.4.1.1.7': #Secondary Capture Image Storage use_dcmspacing = 1 else: use_dcmspacing = 0 imagedata = None if dicom.image.number_of_frames == 1: sx, sy = size n_slices = len(filelist) resolution_percentage = utils.calculate_resizing_tofitmemory( int(sx), int(sy), n_slices, bits / 8) if resolution_percentage < 1.0 and gui: re_dialog = dialog.ResizeImageDialog() re_dialog.SetValue(int(resolution_percentage * 100)) re_dialog_value = re_dialog.ShowModal() re_dialog.Close() if re_dialog_value == wx.ID_OK: percentage = re_dialog.GetValue() resolution_percentage = percentage / 100.0 else: return xyspacing = xyspacing[0] / resolution_percentage, xyspacing[ 1] / resolution_percentage self.matrix, scalar_range, self.filename = image_utils.dcm2memmap( filelist, size, orientation, resolution_percentage) if orientation == 'AXIAL': spacing = xyspacing[0], xyspacing[1], zspacing elif orientation == 'CORONAL': spacing = xyspacing[0], zspacing, xyspacing[1] elif orientation == 'SAGITTAL': spacing = zspacing, xyspacing[1], xyspacing[0] else: print(">>>>>> filelist", filelist) self.matrix, scalar_range, spacing, self.filename = image_utils.dcmmf2memmap( filelist[0], orientation) print(">>>>>> spacing", spacing) self.Slice = sl.Slice() self.Slice.matrix = self.matrix self.Slice.matrix_filename = self.filename self.Slice.spacing = spacing # 1(a): Fix gantry tilt, if any tilt_value = dicom.acquisition.tilt if (tilt_value) and (gui): # Tell user gantry tilt and fix, according to answer message = _("Fix gantry tilt applying the degrees below") value = -1 * tilt_value tilt_value = dialog.ShowNumberDialog(message, value) image_utils.FixGantryTilt(self.matrix, self.Slice.spacing, tilt_value) elif (tilt_value) and not (gui): tilt_value = -1 * tilt_value image_utils.FixGantryTilt(self.matrix, self.Slice.spacing, tilt_value) self.Slice.window_level = wl self.Slice.window_width = ww scalar_range = int(self.matrix.min()), int(self.matrix.max()) Publisher.sendMessage('Update threshold limits list', threshold_range=scalar_range) return self.matrix, self.filename, dicom
def OpenDicomGroup(self, dicom_group, interval, file_range, gui=True): # Retrieve general DICOM headers dicom = dicom_group.GetDicomSample() # Create imagedata interval += 1 filelist = dicom_group.GetFilenameList()[::interval] if not filelist: utils.debug("Not used the IPPSorter") filelist = [i.image.file for i in dicom_group.GetHandSortedList()[::interval]] if file_range is not None and file_range[0] is not None and file_range[1] > file_range[0]: filelist = filelist[file_range[0]:file_range[1] + 1] zspacing = dicom_group.zspacing * interval size = dicom.image.size bits = dicom.image.bits_allocad sop_class_uid = dicom.acquisition.sop_class_uid xyspacing = dicom.image.spacing orientation = dicom.image.orientation_label wl = float(dicom.image.level) ww = float(dicom.image.window) if sop_class_uid == '1.2.840.10008.5.1.4.1.1.7': #Secondary Capture Image Storage use_dcmspacing = 1 else: use_dcmspacing = 0 imagedata = None if dicom.image.number_of_frames == 1: sx, sy = size n_slices = len(filelist) resolution_percentage = utils.calculate_resizing_tofitmemory(int(sx), int(sy), n_slices, bits/8) if resolution_percentage < 1.0 and gui: re_dialog = dialog.ResizeImageDialog() re_dialog.SetValue(int(resolution_percentage*100)) re_dialog_value = re_dialog.ShowModal() re_dialog.Close() if re_dialog_value == wx.ID_OK: percentage = re_dialog.GetValue() resolution_percentage = percentage / 100.0 else: return xyspacing = xyspacing[0] / resolution_percentage, xyspacing[1] / resolution_percentage self.matrix, scalar_range, self.filename = image_utils.dcm2memmap(filelist, size, orientation, resolution_percentage) print(xyspacing, zspacing) if orientation == 'AXIAL': spacing = xyspacing[0], xyspacing[1], zspacing elif orientation == 'CORONAL': spacing = xyspacing[0], zspacing, xyspacing[1] elif orientation == 'SAGITTAL': spacing = zspacing, xyspacing[1], xyspacing[0] else: self.matrix, spacing, scalar_range, self.filename = image_utils.dcmmf2memmap(filelist[0], orientation) self.Slice = sl.Slice() self.Slice.matrix = self.matrix self.Slice.matrix_filename = self.filename self.Slice.spacing = spacing # 1(a): Fix gantry tilt, if any tilt_value = dicom.acquisition.tilt if (tilt_value) and (gui): # Tell user gantry tilt and fix, according to answer message = _("Fix gantry tilt applying the degrees below") value = -1*tilt_value tilt_value = dialog.ShowNumberDialog(message, value) image_utils.FixGantryTilt(self.matrix, self.Slice.spacing, tilt_value) elif (tilt_value) and not (gui): tilt_value = -1*tilt_value image_utils.FixGantryTilt(self.matrix, self.Slice.spacing, tilt_value) self.Slice.window_level = wl self.Slice.window_width = ww scalar_range = int(self.matrix.min()), int(self.matrix.max()) Publisher.sendMessage('Update threshold limits list', threshold_range=scalar_range) return self.matrix, self.filename, dicom