rpt_dosi.images =============== .. py:module:: rpt_dosi.images Attributes ---------- .. autoapisummary:: rpt_dosi.images.image_builders Classes ------- .. autoapisummary:: rpt_dosi.images.MetaImageBase rpt_dosi.images.MetaImageCT rpt_dosi.images.MetaImageSPECT rpt_dosi.images.MetaImagePET rpt_dosi.images.MetaImageROI rpt_dosi.images.MetaImageDose Functions --------- .. autoapisummary:: rpt_dosi.images.read_metaimage rpt_dosi.images.metadata_exists rpt_dosi.images.new_metaimage rpt_dosi.images.get_metaimage_class_from_type rpt_dosi.images.read_metaimage_type_from_metadata rpt_dosi.images.delete_image_metadata rpt_dosi.images.read_ct rpt_dosi.images.read_spect rpt_dosi.images.read_pet rpt_dosi.images.read_roi rpt_dosi.images.read_dose rpt_dosi.images.read_list_of_rois rpt_dosi.images.images_have_same_domain rpt_dosi.images.validate_spacing rpt_dosi.images.images_have_same_spacing rpt_dosi.images.image_has_this_spacing rpt_dosi.images.resample_itk_image_like rpt_dosi.images.resample_itk_image_spacing rpt_dosi.images.image_set_background rpt_dosi.images.get_pixel_value_range rpt_dosi.images.crop_to_bounding_box rpt_dosi.images.convert_ct_to_densities rpt_dosi.images.apply_itk_gauss_smoothing rpt_dosi.images.resample_ct_like rpt_dosi.images.resample_dose_like rpt_dosi.images.resample_ct_spacing rpt_dosi.images.resample_spect_like rpt_dosi.images.resample_spect_spacing rpt_dosi.images.resample_roi_like rpt_dosi.images.resample_roi_spacing rpt_dosi.images.test_compare_images rpt_dosi.images.dilate_mask rpt_dosi.images.mip rpt_dosi.images.image_roi_stats rpt_dosi.images.mhd_find_raw_file rpt_dosi.images.mhd_replace_raw rpt_dosi.images.is_mhd_file rpt_dosi.images.mhd_copy_or_move rpt_dosi.images.copy_or_move_image rpt_dosi.images.get_time_from_injection_h rpt_dosi.images.set_time_from_injection_h rpt_dosi.images.compute_image_extent rpt_dosi.images.compute_combined_fov_extent rpt_dosi.images.create_empty_sitk_image_from_extent rpt_dosi.images.roi_boolean_operation Module Contents --------------- .. py:function:: read_metaimage(file_path, reading_mode='image') Read an existing metaimage. Need both the image and the associated metadata json sidecar file. reading_mode: - image - header_only - metadata_only .. py:function:: metadata_exists(file_path) .. py:function:: new_metaimage(image_type, file_path, overwrite=False, reading_mode='metadata_only', **kwargs) Create (and read) a new metaimage. The filepath of the image must exist. The associated metadata json sidecar file is created (or overwritten if already exist) The required parameters must be given for some image_type : - SPECT require 'unit' - ROI require 'name' .. py:function:: get_metaimage_class_from_type(image_type) .. py:function:: read_metaimage_type_from_metadata(file_path) .. py:function:: delete_image_metadata(file_path) .. py:function:: read_ct(filepath) Read or create a CT image .. py:function:: read_spect(filepath, unit=None) Read or create a SPECT image and consider the given unit .. py:function:: read_pet(filepath, unit=None) Read or create a PET image and consider the given unit .. py:function:: read_roi(filepath, name=None, effective_time_h=None) Read or create a ROI image and consider the given unit .. py:function:: read_dose(filepath, unit=None) Read or create a Dose image and consider the given unit .. py:function:: read_list_of_rois(filename, folder=None) .. py:class:: MetaImageBase(image_path, reading_mode, create=False, **kwargs) Bases: :py:obj:`rpt_dosi.metadata.ClassWithMetaData` Class to manage metadata, providing methods to convert to/from dict and JSON. The class fields that are considered as metadata are store in _metadata_fields. .. py:attribute:: authorized_units :value: [] .. py:attribute:: unit_default_values .. py:attribute:: image_type :value: None .. py:attribute:: unit_converter .. py:attribute:: _metadata_fields .. py:attribute:: image :value: None .. py:attribute:: description :value: '' .. py:attribute:: _acquisition_datetime :value: None .. py:attribute:: body_weight_kg :value: None .. py:attribute:: _image_filename :value: None .. py:attribute:: _image_file_path :value: None .. py:attribute:: _image_header :value: None .. py:attribute:: _unit :value: None .. py:attribute:: _unit_default_value :value: 0 .. py:property:: image_file_path .. py:method:: _init_required_metadata(**kwargs) .. py:method:: ensure_image_is_loaded() .. py:method:: image_is_loaded() .. py:property:: unit .. py:property:: filename .. py:method:: require_unit(unit) .. py:method:: convert_to_unit(new_unit) .. py:property:: voxel_volume_cc .. py:property:: voxel_volume_ml .. py:property:: unit_default_value .. py:property:: acquisition_datetime .. py:method:: read(file_path=None) .. py:method:: write(file_path=None, writing_mode='image') .. py:method:: read_metadata() .. py:method:: read_image_header() .. py:method:: write_metadata() .. py:property:: metadata_file_path .. py:method:: info() .. py:method:: check_file_metadata() .. py:class:: MetaImageCT(image_path, reading_mode, create=False, **kwargs) Bases: :py:obj:`MetaImageBase` Class to manage metadata, providing methods to convert to/from dict and JSON. The class fields that are considered as metadata are store in _metadata_fields. .. py:attribute:: authorized_units :value: ['HU', 'g/cm3'] .. py:attribute:: unit_default_values .. py:attribute:: image_type :value: 'CT' .. py:attribute:: unit :value: 'HU' .. py:method:: compute_densities() .. py:class:: MetaImageSPECT(image_path, reading_mode, create=False, **kwargs) Bases: :py:obj:`MetaImageBase` Class to manage metadata, providing methods to convert to/from dict and JSON. The class fields that are considered as metadata are store in _metadata_fields. .. py:attribute:: authorized_units :value: ['Bq', 'Bq/mL', 'SUV'] .. py:attribute:: unit_default_values .. py:attribute:: image_type :value: 'SPECT' .. py:attribute:: unit_converter .. py:attribute:: _metadata_fields .. py:attribute:: _injection_datetime :value: None .. py:attribute:: injection_activity_mbq :value: None .. py:method:: _init_required_metadata(**kwargs) .. py:property:: injection_datetime .. py:method:: info() .. py:method:: convert_to_bq() .. py:method:: convert_to_bqml() .. py:method:: convert_to_suv() .. py:method:: compute_total_activity() .. py:property:: time_from_injection_h .. py:method:: write_metadata() .. py:class:: MetaImagePET(image_path, reading_mode, create=False, **kwargs) Bases: :py:obj:`MetaImageSPECT` Class to manage metadata, providing methods to convert to/from dict and JSON. The class fields that are considered as metadata are store in _metadata_fields. .. py:attribute:: authorized_units :value: ['Bq/mL', 'SUV'] .. py:attribute:: unit_default_values .. py:attribute:: image_type :value: 'PET' .. py:attribute:: _injection_datetime :value: None .. py:attribute:: injection_activity_mbq :value: None .. py:method:: _init_required_metadata(**kwargs) .. py:class:: MetaImageROI(image_path, reading_mode, create=False, **kwargs) Bases: :py:obj:`MetaImageBase` Class to manage metadata, providing methods to convert to/from dict and JSON. The class fields that are considered as metadata are store in _metadata_fields. .. py:attribute:: authorized_units :value: ['label'] .. py:attribute:: unit_default_values .. py:attribute:: image_type :value: 'ROI' .. py:attribute:: _metadata_fields .. py:attribute:: name :value: None .. py:attribute:: _unit :value: 'label' .. py:attribute:: effective_time_h :value: None .. py:attribute:: mass_g :value: None .. py:attribute:: volume_cc :value: None .. py:method:: _init_required_metadata(**kwargs) .. py:method:: info() .. py:method:: update_mass_and_volume(density_ct) .. py:method:: write_metadata() .. py:class:: MetaImageDose(image_path, reading_mode, create=False, **kwargs) Bases: :py:obj:`MetaImageSPECT` Class to manage metadata, providing methods to convert to/from dict and JSON. The class fields that are considered as metadata are store in _metadata_fields. .. py:attribute:: authorized_units :value: ['Gy', 'Gy/s'] .. py:attribute:: unit_default_values .. py:attribute:: image_type :value: 'Dose' .. py:method:: _init_required_metadata(**kwargs) .. py:data:: image_builders .. py:function:: images_have_same_domain(image1, image2, tolerance=1e-05) .. py:function:: validate_spacing(ctx, param, value) .. py:function:: images_have_same_spacing(image1, image2, tolerance=1e-05) .. py:function:: image_has_this_spacing(image1, spacing, tolerance=1e-05) .. py:function:: resample_itk_image_like(img, like_img, default_pixel_value, linear) .. py:function:: resample_itk_image_spacing(img, new_spacing, default_pixel_value, linear) .. py:function:: image_set_background(ct, roi, bg_value=-1000, roi_bg_value=0) .. py:function:: get_pixel_value_range(pixel_type) .. py:function:: crop_to_bounding_box(img, lover_threshold=-1000) .. py:function:: convert_ct_to_densities(ct) .. py:function:: apply_itk_gauss_smoothing(img, sigma) .. py:function:: resample_ct_like(ct: MetaImageCT, like: MetaImageBase, gaussian_sigma=None) .. py:function:: resample_dose_like(dose: MetaImageDose, like: MetaImageBase, gaussian_sigma=None) .. py:function:: resample_ct_spacing(ct: MetaImageCT, spacing, gaussian_sigma=None) .. py:function:: resample_spect_like(spect: MetaImageSPECT, like: MetaImageBase, gaussian_sigma=None) .. py:function:: resample_spect_spacing(spect: MetaImageSPECT, spacing, gaussian_sigma=None) .. py:function:: resample_roi_like(roi: MetaImageROI, like: MetaImageBase) .. py:function:: resample_roi_spacing(roi: MetaImageROI, spacing) .. py:function:: test_compare_images(image1, image2, tol=1e-06) .. py:function:: dilate_mask(img, dilatation_mm) .. py:function:: mip(img, dim3=False) .. py:function:: image_roi_stats(roi, spect, ct=None, resample_like='spect') .. py:function:: mhd_find_raw_file(mhd_file_path) .. py:function:: mhd_replace_raw(mhd_file_path, new_raw_filename) .. py:function:: is_mhd_file(file_path) .. py:function:: mhd_copy_or_move(mhd_path, new_mhd_path, mode='copy') .. py:function:: copy_or_move_image(source_path, dest_path, mode) .. py:function:: get_time_from_injection_h(injection_datetime, acquisition_datetime) .. py:function:: set_time_from_injection_h(injection_datetime, acquisition_datetime, time_from_injection_h) .. py:function:: compute_image_extent(sitk_image) .. py:function:: compute_combined_fov_extent(sitk_image1, sitk_image2) .. py:function:: create_empty_sitk_image_from_extent(combined_extent_min, combined_extent_max, spacing, pixel_type=sitk.sitkFloat32) .. py:function:: roi_boolean_operation(sitk_img1, sitk_img2, bool_operator, spacing=None)