cvasl.carve module

Copyright 2023 Netherlands eScience Center and the Amsterdam University Medical Center. Licensed under the Apache License, version 2.0. See LICENSE for details.

This file contains methods to anonymize image files. Specifically we have a methods to get the image out of DICOMs, and to strip soft tissues off head MRIs.

Note the package has an optional pydicom dependancy, without it this module has functions related to dicoms that will not work.

The pydicom is currently shut off.

class cvasl.carve.DirectorySource(directory, tag)

Bases: object

Class to aid reading DICOMs, package agnostically

get_tag()
items(reader, transformer=None)
class cvasl.carve.GlobSource(exp, tag, recursive=True)

Bases: object

Class to aid finding files from path (for later reading out DICOM)

get_tag()
items(reader, transformer=None)
class cvasl.carve.MetadataHelper(reader)

Bases: object

Class for getting DICOM metadata with SimpleITK.

fetch_image(dicom_file)

Read the pixel data of the DICOM image. :param dicom_file: The file to extract image data from. :type dicom_file: str :return: Pixel array of the extracted image. :rtype: ndarray

fetch_metadata(dicom_file)

Reads enough of the DICOM file to fetch its metadata. :param dicom_file: The file for which to read the metadata. :type dicom_file: str :return: Parsed metadata. :rtype: dict

class cvasl.carve.MultiSource(tag, *sources)

Bases: object

get_tag()
items(reader, transformer=None)
class cvasl.carve.SimpleITKDicomReader(date_fields=None, time_fields=None, exclude_fields=None)

Bases: object

Class for reading DICOM metadata with SimpleITK.

date_fields = {'Content Date', 'Series Date', 'Study Date'}

Default fields in the parsed DICOM file to be interpreted as date.

dicom_date_to_date(source)

Utility method to parse DICOM dates to Python’s date. :param source: DICOM date given as string. :type source: str :return: Pyton date object. :rtype: date.

dicom_time_to_time(source)

Utility method to help translate DICOM date and time objects to python datetime.

Warning

This isn’t implemented yet. Needs research on DICOM time representation.

Parameters:

source (str) – Date and time stored in DICOM as a string.

Returns:

Python’s datetime object.

Return type:

datetime

exclude_fields = {}

Default fields to exclude from dataframe generated form DICOM files.

read(source)
time_fields = {'Content Time', 'Study Time'}

Default fields in the parsed DICOM file to be interpreted as datetime.

cvasl.carve.rename_file(original, target, ext)
cvasl.carve.rip_out_array_sitk(dicomfile_directory)

This function is to rip raays out of a dicom file directory, one by one, each of them (not just the first series as), and they can be assigned to a variable.

Parameters:

dicomfile_directory (str) – dicomfile_directory, directory with dicom/.dcm

Returns:

List of images represented as NumPy arrays.

Return type:

List[numpy.ndarray]