question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

image data reader and LoadImage transform refactoring

See original GitHub issue

This is a follow-up of #856 to track the progress of a preliminary IO refactoring.

Goal

The main goal of this ticket is to create a file format agnostic wrapper for the image inputs (LoadImage and LoadImaged). A typical use case (enhancing the current NiftiDataset) is:

train_ds = ImageDataset(images, segs, transform=train_imtrans, seg_transform=train_segtrans)

where images and segs are filenames, ImageDataset internally invokes LoadImage.

Or using a generic monai Dataset API, specify the first component of train_imtrans as a LoadImage transform that extracts data array and meta data from the file.

More specifically:

Reader (file format-specific component)

  1. [format]reader are themselves monai data components (users can use the readers without going through the LoadImage logic), they call external package APIs
  2. [format]reader share the same superclass ImageReader interface (for handling physical/voxel resolution, orientation…)
class ImageReader:
    def get_data(self, ...):
        # return the data in the designated resolution, orientation, 
        # image channel selector, the relevant coordinates, datatype
    
    def read(self, ...):
        # create an IO object instance or a set of instances
  1. users can make customized MyReader by implementing the ImageReader interface
  2. the customized MyReader could be registered with the LoadImage factory
@register_reader(requires='my_external_library')
class MyReader(ImageReader):
    ...

LoadImage(file format agnostic component)

  1. LoadImage is a monai transform
  2. LoadImaged should return the same underlying data representation dictionary regardless of the image format.
  3. LoadImage may choose a suitable [format]reader dynamically at runtime based on the following rules (ordered from high to low priority):
  • user’s selection of a specific reader, such as LoadImage(reader='ITkReader')
  • try any user-registered readers
  • try resources map based on a global property file and filename extensions:
MONAI.IO
{
    FOO LoadFOO
    PNG  ITK/5.1/LoadITK
    TIFF,TIF  ITK/5.1/LoadITK
    * ITK/5.1/LoadITK
}
  • fails early and preserves detailed error messages

additional requirements

  • should be able to specify versions of external reader to ensure reproducibility
  • need to have consistent coordinate systems, resolution conventions

tasks

  • implement interface ImageReader, factory (transforms) LoadImage LoadImaged
  • implement ITKReader, NibabelReader, NumpyReader, PILReader?
  • LoadImage selecting readers according to the preference list
  • new interfaces tutorial https://github.com/Project-MONAI/Tutorials/pull/19
  • deprecate NiftiDataset, add ImageDataset
  • deprecate LoadNifti, LoadPNG, LoadNumpy, LoadDatad
  • revise/check all examples demos

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
wylicommented, Aug 18, 2020

thanks for the discussion @Nic-Ma let’s use this ticket to raise any detailed technical issues

1reaction
Nic-Macommented, Jan 14, 2021

Will deprecate NiftiDataset, add ImageDataset in another separate PR later. Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Performing basic image processing over multiple images
Per drone mission (consisting of about 250 images), I want to add a single image, transform to grayscale, calculate the variance in pixels ......
Read more >
Loading Images - Vulkan Guide
We are going to have a single load-image function, that will do the whole load operation from file in disk into GPU memory....
Read more >
C# & SQLite - Storing Images - CodeProject
How to insert images / binary data into a database. ... uses another method called LoadImage which handles the binary reading of an...
Read more >
monai.transforms.io.array — MONAI 0.5.0 documentation
__name__}") return data. [docs]class LoadImage(Transform): """ Load image file or files from provided path based on reader. Automatically choose readers ...
Read more >
Processing Overview / Processing.org
... that support more advanced features such as sending data over a network, reading live images from a webcam, and saving complex imagery...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found