Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tensoflow dataset_from_dicom_filesnames #29

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

blowekamp
Copy link
Member

Add method to create a Tensorflow Dataset flow from a list of filenames readable by SimpleITK.

Add method to create a Tensorflow Dataset flow from a list of
filenames readable by SimpleITK.
@blowekamp blowekamp requested a review from zivy May 22, 2023 15:08
Copy link
Member

@zivy zivy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really like it, especially the lazy loading via map and the _sitk_read_image function.



def _sitk_read_image(
filename: tf.string, image_path=None, encoding="utf-8", channels=3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image_path - possibly rename to image_dir_path?

"""

image = sitk.RescaleIntensity(image, outputMinimum=0.0, outputMaximum=255.0)
image = sitk.Cast(image, sitk.sitkUInt8)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these two rows should be removed (rescale+cast). The DICOM images can be color.

if image.GetDimension() == 3 and image.GetSize()[2] == 1:
image = image[:, :, 0]

if image.GetDimension() == 2:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably also allow for 3D images.

if image_path:
str_fn = str(Path(image_path) / str_fn)

image = sitk.ReadImage(str_fn, sitk.sitkFloat32)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set the IO to GDCM? This is so that it matches the intent of dataset_from_dicom_filenames. Or just change that function name to dataset_from_filenames?

@blowekamp
Copy link
Member Author

Please describe the expected behavior and features at a higher level and not at the if statements.

This code is a not terrible specific to "DICOM" except the conversion of 3D of 1 slice to 2D. Adding support for "series" would be an additional feature more specific for 3D DICOM series. This was originally written for support for 2D chest x-ray images.

@zivy
Copy link
Member

zivy commented May 23, 2023

The code indeed is not DICOM specific. I think a more general interface makes sense.

A function dataset_from_filenames receives filenames that are either 2D or 3D both scalar and multi-channel. Pseudo 3D (x_size, y_size, 1) is converted to 2D (x_size, y_size) as done in the code. Reading remains as is, no need to specify ImageIO, so all file types supported by SimpleITK. User is responsible to ensure that all files result in the same tensor structure (no mixing of 2D and 3D, 2D color and 2D scalar etc.).

No need to support 3D images as series of files. Users should convert a series to a single 3D image prior to training as the read operation is much faster (will be very slow if all volumes are represented by series of images).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants