deid.dicom.pixels package

Submodules

deid.dicom.pixels.clean module

class deid.dicom.pixels.clean.DicomCleaner(output_folder=None, add_padding=False, margin=3, deid=None, font=None, force=True)[source]

Bases: object

Clean a dicom file of burned pixels.

take an input dicom file, check for burned pixels, and then clean, with option to save / output in multiple formats. This object should map to one dicom file, and the usage flow is the following: cleaner = DicomCleaner() summary = cleaner.detect(dicom_file)

cleaner.clean()

clean(fix_interpretation: bool = True, pixel_data_attribute: str = 'PixelData')Optional[numpy.ndarray[Any, numpy.dtype[ScalarType]]][source]
default_font()[source]

Get the default font to use for a title.

define the font style for saving png figures if a title is provided

detect(dicom_file)[source]

Initiate the cleaner for a new dicom file.

get_figure(show=False, image_type='cleaned', title=None)[source]

Get a figure for an original or cleaned image.

If the image was already clean, it is simply a copy of the original. If show is True, plot the image. If a 4d image is discovered, we use randomly choose a slice.

save_animation(output_folder=None, image_type='cleaned', title=None)[source]

Save an original or cleaned animation of a dicom.

If there are not enough frames, then save_png should be used instead.

save_dicom(output_folder=None, image_type='cleaned')[source]

Save a cleaned dicom to disk.

We expose an option to save an original (change image_type to “original” to be consistent, although this is not incredibly useful given it would duplicate the original data.

save_png(output_folder=None, image_type='cleaned', title=None)[source]

Save an original or cleaned dicom as png to disk.

Default image_format is “cleaned” and can be set to “original.” If the image was already clean (not flagged) the cleaned image is just a copy of original. If a 4d image is provided, we save the dimension specified (or if not provided, a randomly chosen dimension).

deid.dicom.pixels.clean.clean_pixel_data(dicom_file, results: dict, fix_interpretation: bool = True, pixel_data_attribute: str = 'PixelData')[source]

Clean a dicom file.

take a dicom image and a list of pixel coordinates, and return a cleaned file (if output file is specified) or simply plot the cleaned result (if no file is specified)

Parameters:
  • dicom_file ((str or FileDataset instance) Dicom file to clean) –
  • results (Result of the .has_burned_pixels() method) –
  • fix_interpretation (fix the photometric interpretation if found off) –
  • pixel_data_attribute (PixelData attribute name in the dicom file) –

deid.dicom.pixels.detect module

deid.dicom.pixels.detect.evaluate_group(flags)[source]

Evaluate group will take a list of flags (e.g.,

[True, and, False, or, True]

And read through the logic to determine if the image result is to be flagged. This is how we combine a set of criteria in a group to come to a final decision.

deid.dicom.pixels.detect.extract_coordinates(dicom, field)[source]

Given a field that is provided for a dicom, extract coordinates

deid.dicom.pixels.detect.has_burned_pixels(dicom_files, force: bool = True, deid: Optional[deid.config.DeidRecipe] = None)[source]

Determine if a dicom file has burned pixels.

has_burned_pixels is an entrypoint for has_burned_pixels_multi (for multiple images) or has_burned_pixels_single (for one detailed repor) We will use the MIRCTP criteria (see ref folder with the original scripts used by CTP) to determine if an image is likely to have PHI, based on fields in the header alone. This script does NOT perform pixel cleaning, but returns a dictionary of results (for multi) or one detailed result (for single)

Module contents