io3d package

Subpackages

Module datareader

Module for readin 3D dicom data

class io3d.datareader.DataReader[source]
Get3DData(datapath, qt_app=None, dataplus_format=True, gui=False, start=0, stop=None, step=1, convert_to_gray=True, series_number=None, use_economic_dtype=True, **kwargs)[source]

:datapath directory with input data :qt_app if it is set to None (as default) all dialogs for series selection are performed in terminal. If qt_app is set to QtGui.QApplication() dialogs are in Qt.

:dataplus_format is new data format. Metadata and data are returned in one structure.

GetOverlay()[source]

Generates dictionary of ovelays

read_hdf5(datapath)[source]

Method is not implemented

io3d.datareader.get_datapath_qt(qt_app)[source]
io3d.datareader.main()[source]
io3d.datareader.read(datapath, qt_app=None, dataplus_format=True, gui=False, start=0, stop=None, step=1, convert_to_gray=True, series_number=None, **kwargs)[source]

Simple read function. Internally call DataReader.Get3DData()

Module datawriter

class io3d.datawriter.DataWriter[source]
DataCopyWithOverlay(dcmfilelist, out_dir, overlays)[source]

Function make 3D data from dicom file slices

:dcmfilelist list of sorted .dcm files :overlays dictionary of binary overlays. {1:np.array([…]), 3:…} :out_dir output directory

Write3DData(data3d, path, filetype='auto', metadata=None, progress_callback=None, sfin=True)[source]
Parameters:
  • data3d – input ndarray data
  • path – output path, to specify slice number advanced formatting options (like {:06d}) can be used

Check function filename_format() for more details. :param metadata: {‘voxelsize_mm’: [1, 1, 1]} :param filetype: dcm, vtk, rawiv, image_stack :param progress_callback: fuction for progressbar f.e. callback(value, minimum, maximum) :param sfin: Use separate file for segmentation if necessary

add_overlay_to_slice_file(filename, overlay, i_overlay, filename_out=None)[source]

Function adds overlay to existing file.

encode_overlay_slice(data, overlay, i_overlay)[source]
save_hdf5(data3d, path, metadata)[source]
save_image_stack(data3d, filepattern, metadata=None)[source]
stop()[source]
io3d.datawriter.filename_format(filepattern, series_number=1, slice_number=0, slice_position=0.0)[source]
Parameters:filepattern – advanced format options can be used in filepattern.

Fallowing keys can be used: slice_number, slicen, series_number, seriesn, series_position, seriesp. For example ‘{:06d}.jpg’, ‘{series_number:03d}/{slice_position:07.3f}.png’ :param series_number: :param slice_number: :param slice_position: :param change_series_number_if_file_exists: :return:

io3d.datawriter.filepattern_fill_series_number(filepattern, series_number)[source]
io3d.datawriter.filepattern_fill_slice_number_or_position(filepattern, slice_description)[source]
io3d.datawriter.get_first_filename(filepattern, series_number=None)[source]
io3d.datawriter.get_unoccupied_series_number(filepattern, series_number=1)[source]
io3d.datawriter.saveOverlayToDicomCopy(input_dcmfilelist, output_dicom_dir, overlays, crinfo, orig_shape)[source]

Save overlay to dicom.

io3d.datawriter.write(data3d, path, filetype='auto', metadata=None)[source]
Parameters:
  • data3d – input ndarray
  • path – output path, if braces are in the name (“dir/file{:04d}.dcm”), image stack is produced .

Check function filename_format() for more details. :param filetype: dcm, png, h5, … “image_stack” :param metadata: metadata f.e. {‘voxelsize_mm’: [3,2,2]} :return:

Module datasets

Module is used for visualization of segmentation stored in pkl file.

io3d.datasets.checksum(path, hashfunc='md5')[source]

Return checksum given by path. Wildcards can be used in check sum. Function is strongly dependent on checksumdir package by ‘cakepietoast’.

Parameters:
  • path
  • hashfunc
Returns:

io3d.datasets.dataset_path(cache=None, cachefile='~/io3d_cache.yaml')[source]

Get dataset path. :param cache: CacheFile object :param cachefile: cachefile path :return:

io3d.datasets.download(dataset_label=None, destination_dir=None, dry_run=False)[source]

Download sample data by data label. Labels can be listed by sample_data.data_urls.keys() :param dataset_label: label of data. If it is set to None, all data are downloaded :param destination_dir: output dir for data :return:

io3d.datasets.downzip(url, destination='./sample_data/')[source]

Download, unzip and delete.

io3d.datasets.generate_abdominal(size=100, liver_intensity=100, noise_intensity=20, portal_vein_intensity=130, spleen_intensity=90)[source]
io3d.datasets.generate_donut()[source]

Generate donut like shape with stick inside

Returns:datap with keys data3d, segmentation and voxelsize_mm
io3d.datasets.get(dataset_label, series_number=None, *args, **kwargs)[source]
Parameters:
  • dataset_label – label from data_urls
  • series_number – Series identification in study.
  • args
  • kwargs
Returns:

io3d.datasets.get_dataset_meta(label)[source]
io3d.datasets.get_old(dataset_label, id, destination_dir=None)[source]

Get the 3D data from specified dataset with specified id.

Download data if necessary.

Parameters:
  • dataset_label
  • id – integer or wildcards file pattern
  • destination_dir
Returns:

io3d.datasets.join_path(*path_to_join)[source]

join input path to sample data path (usually in ~/lisa_data) :param path_to_join: one or more paths :return:

io3d.datasets.main()[source]
io3d.datasets.remove(local_file_name)[source]
io3d.datasets.set_dataset_path(path, cache=None, cachefile='~/io3d_cache.yaml')[source]
io3d.datasets.sliver_reader(filename_end_mask='*[0-9].mhd', sliver_reference_dir='~/data/medical/orig/sliver07/training/', read_orig=True, read_seg=False)[source]

Generator for reading sliver data from directory structure.

Parameters:
  • filename_end_mask – file selection can be controlled with this parameter
  • sliver_reference_dir – directory with sliver .mhd and .raw files
  • read_orig – read image data if is set True
  • read_seg – read segmentation data if is set True
Returns:

numeric_label, vs_mm, oname, orig_data, rname, ref_data

io3d.datasets.unzip_one(local_file_name)[source]

Unzip one file and delete it. :param local_file_name: file name of zip file :return:

io3d.datasets.unzip_recursive(zip_file_name)[source]

Unzip file with all recursive zip files inside and delete zip files after that.

Parameters:zip_file_name
Returns:

Module dcmreaddata

DICOM reader

Example:

$ dcmreaddata -d sample_data -o head.mat

class io3d.dcmreaddata.DicomDirectory(dirpath, force_create_dicomdir=False, force_read=False)[source]
create_standard_dicomdir()[source]

Create standard dicom dir describing files in directory. See read_standard_dicomdir_info() and get_standard_dicomdir_info() :return:

get_metaData(dcmlist, series_number, ifile=0)[source]

Get metadata. Voxel size is obtained from PixelSpacing and difference of SliceLocation of two neighboorhoding slices (first have index ifile). Files in are used.

get_metadata_new(series_number)[source]

Return series metadata. Output condatin information about voxelsize_mm, series_number and modality. If it is possible, the ImageComment, AcquisitionDate and few other dicom tags are also in output dict. :param series_number: :return: metadata dict with voxelsize_mm, SeriesNumber and other dicom tags

get_sorted_series_files(startpath='', series_number=None, return_files_with_info=False, sort_keys='SliceLocation', return_files=True)[source]

Function returns sorted list of dicom files. File paths are organized by SeriesUID, StudyUID and FrameUID

Parameters:
  • startpath – path prefix. E.g. “~/data”
  • series_number – ID of series used for filtering the data
  • return_files_with_info – return more complex information about sorted files
  • return_files – return simple list of sorted files
get_standard_dicomdir_info()[source]

Read DICOMDIR, crate if necessary. :return:

get_stats_of_series_in_dir(study_id=None)[source]

Dicom series staticstics, input is dcmdir, not dirpath Information is generated from dicomdir.pkl and first files of series

get_stats_of_studies_and_series_in_dir()[source]
get_study_info(series_info=None)[source]
get_study_info_msg(series_info=None)[source]
print_series_info(series_info, minimal_series_number=1)[source]

Print series_info from dcmdirstats

read_standard_dicomdir_info()[source]

Read standard DICOMDIR file :return:

series_in_dir()[source]

input is dcmdir, not dirpath

class io3d.dcmreaddata.DicomReader(dirpath=None, initdir='.', qt_app=None, gui=True, series_number=None, get_series_number_callback=None, force_create_dicomdir=False, force_read=False)[source]

Example:

dcr = DicomReader(os.path.abspath(dcmdir)) data3d = dcr.get_3Ddata() metadata = dcr.get_metaData()

dcmdirstats()[source]
get_3Ddata(start=0, stop=None, step=1)[source]

Function make 3D data from dicom file slices

get_4d()[source]
get_metaData(ifile=0)[source]
get_overlay()[source]

Function make 3D data from dicom file slices. There are usualy more overlays in the data.

print_series_info(*argw, **kwargs)[source]
set_series_number(series_number)[source]
validData()[source]
io3d.dcmreaddata.attr_to_dict(obj, attr, dct)[source]

Add attribute to dict if it exists. :param dct: :param obj: object :param attr: object attribute name :return: dict

io3d.dcmreaddata.decode_overlay_slice(data, i_overlay)[source]
io3d.dcmreaddata.dicomdir_info(dirpath, *args, **kwargs)[source]

Get information about series in dir

io3d.dcmreaddata.files_in_dir(dirpath, wildcard='*', startpath=None)[source]

Function generates list of files from specific dir

files_in_dir(dirpath, wildcard=”.”, startpath=None)

dirpath: required directory wilcard: mask for files startpath: start for relative path

Example files_in_dir(‘medical/jatra-kiv’,’*.dcm’, ‘~/data/’)

io3d.dcmreaddata.get_dcmdir_qt(app=False, directory='')[source]
io3d.dcmreaddata.get_one_serie_info(series_info, serie_number)[source]
io3d.dcmreaddata.get_series_number(dcmdata)[source]
io3d.dcmreaddata.get_series_number_console(dcmreader, counts, bins, qt_app=None)[source]
io3d.dcmreaddata.get_series_number_qt(dcmreader, counts, bins, qt_app=None)[source]
io3d.dcmreaddata.get_slice_location(dcmdata, teil=None)[source]

get location of the slice

Parameters:
  • dcmdata – dicom data structure
  • teil – filename. Used when slice location doesnt exist
Returns:

io3d.dcmreaddata.is_dicom_dir(datapath)[source]

Check if in dir is one or more dicom file. We use two methods. First is based on dcm extension detection.

io3d.dcmreaddata.sort_list_of_dicts(lst_of_dct, keys, reverse=False, **sort_args)[source]

Sort by defined keys.

If the key is not available, sort these to the end.

Parameters:
  • lst_of_dct
  • keys
  • reverse
  • sort_args
Returns:

Module misc

io3d.misc.obj_from_file(filename='annotation.yaml', filetype='auto')[source]

Read object from file

io3d.misc.obj_to_file(obj, filename, filetype='auto', ndarray_to_list=False, squeeze=True)[source]

Writes annotation in file.

Parameters:
  • filetype – auto yaml pkl, pickle pklz, picklezip
  • ndarray_to_list – convert ndarrays in obj to lists
  • squeeze – squeeze ndarray
io3d.misc.old_str_format_to_new(string)[source]

convert old format style to new style. Works for digits only %05d is converted to {:05d} :param string: :return:

io3d.misc.read_pkl_and_pklz(filename)[source]

Try read zipped or not zipped pickle file

io3d.misc.resize_to_mm(data3d, voxelsize_mm, new_voxelsize_mm, mode='nearest')[source]

Function can resize data3d or segmentation to specifed voxelsize_mm :new_voxelsize_mm: requested voxelsize. List of 3 numbers, also

can be a string ‘orig’, ‘orgi*2’ and ‘orgi*4’.
Voxelsize_mm:size of voxel
Mode:default is ‘nearest’
io3d.misc.resize_to_shape(data, shape, zoom=None, mode='nearest', order=0)[source]

Function resize input data to specific shape.

Parameters:
  • data – input 3d array-like data
  • shape – shape of output data
  • zoom – zoom is used for back compatibility
Mode:

default is ‘nearest’

io3d.misc.suggest_filename(file_path, exists=None)[source]

Try if exist path and append number to its end. For debug you can set as input if file exists or not.

io3d.misc.suits_with_dtype(mn, mx, dtype)[source]

Check whether range of values can be stored into defined data type. :param mn: range minimum :param mx: range maximum :param dtype: :return:

io3d.misc.use_economic_dtype(data3d, slope=1, inter=0, dtype=None)[source]

Use more economic integer-like dtype if it is possible.

Parameters:
  • data3d
  • dtype – if dtype is not used, the automatic is used
Returns:

Module datareaderqt

io3d.datareaderqt.main()[source]
io3d.datareaderqt.my_after_fcn(arg)[source]
io3d.datareaderqt.my_before_fcn(arg)[source]