Code

Base Attributes

dicom_wsi.mods.base_attributes.build_base(cfg, instance=1)

Creates the initial file and configuration, as well as sets defaults and 1st level data.

Parameters:
  • cfg – dictionary of input values
  • instance – ‘BaseAttributes’ in case we wanted to use this function later
Returns:

DICOM and new config files

Character Validation

Input Validation

dicom_wsi.mods.input_validation.validate_cfg(cfg)

Validate the dictionary to make sure all the required elements are present :param cfg: a dictionary of values, separated by module name :return: 0

Mapping Functions

Whole Slide Image Parsing

Down-sampling the WSI

dicom_wsi.mods.pixel_data_conversion.resize_wsi_image(wsi=None, series_downsample=0)

reshape the pyvips object to the desired size based on series downsample

Parameters:
  • wsi – PyVIPS Object
  • series_downsample – How many times to downsample
Returns:

byte string to use as the pixel array

Converting Pixels to Positions

dicom_wsi.mods.pixel_to_slide_conversions.add_imgdata(imlist, ds, tile_size, compression_type, compression_quality)

Calls the compression algorithm and add to DICOM object

Parameters:
  • imlist – list of images to compress
  • ds – DICOM object
  • tile_size – how large the image tiles should be
  • compression_type – name of compression scheme
  • compression_quality – quality of compression
Returns:

DICOM object with pixel data

dicom_wsi.mods.pixel_to_slide_conversions.add_per_frame_functional_groups_sequence(img=None, ds=None, cfg=None, tile_size=500, series_downsample=1)

Calculate the PerFrame Functional Groups

Parameters:
  • img – VIPS image object
  • ds – DICOM Object
  • cfg – Config dictionary
  • tile_size – how big should each sub image be?
  • series_downsample – Factor to translate between inches and pixels
Returns:

None

dicom_wsi.mods.pixel_to_slide_conversions.compute_slide_offsets_from_pixel_data(ds=None, row=None, col=None, series_downsample=1)

Calculate the x and y coordinate in slide space

Parameters:
  • ds – some sort of DICOM object
  • row – tile row number [Dimension Index Values (0020,9157)]
  • col – tile column number [Dimension Index Values (0020,9157)]
  • series_downsample – number that indicates how many divisions to apply (1 means no downsample, i.e. level 0)
Returns:

x (0040,072a), y (0040,073a), and z (0040,074a) offsets

dicom_wsi.mods.pixel_to_slide_conversions.define_plane_position_slide_sequence(x, y, z, x_tile, y_tile, x_pos, y_pos)

Build up the sequence position structure for the coordinates

Parameters:
  • x – offset position on slide
  • y – offset position on slide
  • z – offset position on slide (usually 1)
  • x_tile – tile position number
  • y_tile – tile position number
  • x_pos – pixel position
  • y_pos – pixel position
Returns:

a dataset value to be appended to the PerFrameFunctionalGroupsSequence

dicom_wsi.mods.pixel_to_slide_conversions.ensure_even_image(tmp, tile_size)

Images must be an even before being compressed

Parameters:
  • tmp – numpy array of image values
  • tile_size – desired output size
Returns:

an even numbered shape for the numpy array

dicom_wsi.mods.pixel_to_slide_conversions.generate_xy_tiles(x_max, y_max, tile_size=500)

Iterate through the slide with a step size of tile_size

Parameters:
  • x_max
  • y_max
  • tile_size
Returns:

( tile position on the x plane, tile position on the y plane, index of the tile on the x plane, index of the tile on the y plane)

Adding in Sequence Data

dicom_wsi.mods.sequence_attributes.build_sequences(dcm)

all values are hard coded to ensure they are present in the final file

Adding Functional Groups Data

dicom_wsi.mods.shared_functional_groups.build_functional_groups(dcm, cfg)

all values are hard coded to ensure they are present in the final file

Other helper utilities

dicom_wsi.mods.utils.add_data(ds, k, v, cfg, dict_element=None)

Ensures the right kind of data is insreted into DICOM object (e.g. datetime, time, date, etc)

Parameters:
  • ds – DICOM dataset
  • k – DICOM keyword
  • v – Value to set keyword
  • cfg – config dict
  • dict_element – which part of processing is this coming from
Returns:

dicom_wsi.mods.utils.get_all_keys(d, prefix=False)

Return a list of all keys (even nested ones from dict

Parameters:
  • d – nested dictionary
  • prefix – Whether or not to provide dot notation to keep the nesting information
Returns:

list of keys

dicom_wsi.mods.utils.get_info_from_keyword(kw)

Get Value data from Keywords

Parameters:kw – KeyWord
Returns:VR, VM, NAME, ISRETIRED, KW

pydicom.datadict.get_entry(‘StudyDate’) (‘DA’, ‘1’, ‘Study Date’, ‘’, ‘StudyDate’)

dicom_wsi.mods.utils.make_date(k, date_var, cfg, dict_element='BaseAttributes')

Need to make sure it return the format YYYYMMDD, or return a new one

Parameters:
  • k – key
  • date_var – value
  • cfg – config file
  • dict_element – which section/module the attributes belong to
Returns:

updated config dictionary

dicom_wsi.mods.utils.make_datetime(k, datetime_var, cfg, dict_element='BaseAttributes')

Need to make sure it return the format YYYYMMDDHHMMSS.FFFFFF, or return a new one

Parameters:
  • k – key
  • datetime_var – value
  • cfg – config file
  • dict_element – which section/module the attributes belong to
Returns:

updated config dictionary

dicom_wsi.mods.utils.make_time(k, time_var, cfg, dict_element='BaseAttributes')

Need to make sure it return the format HHMMSS.FFFFFF, or return a new one

Parameters:
  • k – key
  • time_var – value
  • cfg – config file
  • dict_element – which section/module the attributes belong to
Returns:

updated config dictionary

dicom_wsi.mods.utils.uid_maker(k, v, cfg, dict_element='BaseAttributes')

Make a UID if needed

Parameters:
  • k – key
  • v – value
  • cfg – config file
  • dict_element – which section/module the attributes belong to
Returns:

updated config dictionary