InsightSoftwareConsortium / ITKTubeTK

TubeTK is an open-source toolkit for the segmentation, registration, and analysis of tubes and surfaces in images, developed by Kitware, Inc.
Apache License 2.0
47 stars 57 forks source link

ConvertTubesToImage.ipynb generates discontinious vessels #81

Closed Subhashis-Banerjee closed 3 years ago

Subhashis-Banerjee commented 3 years ago

snapshot0001

aylward commented 3 years ago

Thanks for trying TubeTK.

Two things could make that happen:

1) The resolution of the image that you are creating from the tre file is too coarse compared to the resolution (radius) of the tubes. For example, if your tubes have a radius of 1mm and your image has a resolution of 3x3x3mm, then gaps could appear.

2) The method that you're using to show the data in the image as surfaces is creating gaps. Some marching cubes and triangle decimation implementations will not properly create surfaces that represent one-voxel-wide tubes - so gaps result.

So, please look at the image slice-by-slice and see if there are actually gaps in the image data. If so, then the resolution of the image needs to be increased. If not, then the method used to generate surfaces from the image needs to be checked.

One thing you might want to do, if your goal is to create a surface rendering, is to bypass the creation of an image from the .tre file and instead use the ConvertTubesToSurface application.

Hope this helps, Stephen

Subhashis-Banerjee commented 3 years ago

Hi Stephen, thanks for the detailed explanation.

I am using the ITKTubeTK - Bullitt - Healthy MR Database "https://data.kitware.com/#collection/591086ee8d777f16d01e0724/folder/58a372e38d777f0721a64dc6".

In the dataset for some patients "VascularNetwork.tre" files are available.

I want to convert it into a binary segmentation mask (.nii or .mha)

So, my question is can I use the VascularNetwork.tre as segmentation ground truth?

And I am following the steps mentioned in https://github.com/InsightSoftwareConsortium/ITKTubeTK/blob/master/examples/Demo-ConvertTubesToImage.ipynb

Also in 2D viewers discontinuity is observed (sample image attached) snapshot0001

Thanks, Subhashis

aylward commented 3 years ago

Let's see if there are gaps in the .tre file.

Could you please drag-and-drop your VascularNetwork.tre file onto this viewer: https://paraview-medical.netlify.app/

The 2D renderings are really messed up, but the 3D renderings look right. I just tried this on the VascularNetwork.tre file from Normal-044 in that collection. There are no gaps in the tre file.

You could also drag-and-drop your image file that is generated by the ConvertTubesToImage function onto this application. That will generate a volume rendering of the mask (instead of extracting surfaces) and will let you see if the image file really has gaps (it is hard to tell from a 2D slice since sometimes the vessel is passing through an adjacent slice instead of the one shown).

On Tue, Aug 31, 2021 at 10:05 AM Subhashis Banerjee < @.***> wrote:

Hi Stephen, thanks for the detailed explanation.

I am using the ITKTubeTK - Bullitt - Healthy MR Database " https://data.kitware.com/#collection/591086ee8d777f16d01e0724/folder/58a372e38d777f0721a64dc6 ".

In the dataset for some patients "VascularNetwork.tre" files are available.

I want to convert it into a binary segmentation mask (.nii or .mha)

So, my question is can I use the VascularNetwork.tre as segmentation ground truth?

And I am following the steps mentioned in https://github.com/InsightSoftwareConsortium/ITKTubeTK/blob/master/examples/Demo-ConvertTubesToImage.ipynb

Also in 2D viewers discontinuity is observed (sample image attached) [image: snapshot0001] https://user-images.githubusercontent.com/20064427/131516930-620d842d-6f6d-4f4d-8130-2f166fb34bee.png

Thanks, Subhashis

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/InsightSoftwareConsortium/ITKTubeTK/issues/81#issuecomment-909269802, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACEJL74J3DI7EWD37FASLLT7TORRANCNFSM5DCS3C5Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

-- Stephen R. Aylward, Ph.D. Senior Director of Strategic Initiatives

Kitware: Delivering innovative, open source, scientific software.

aylward commented 3 years ago

Hi,

You will need to upsample the image for those small vessels to appear in the mask.

In TubeTK you could use the ResampleImage command for this. I suggest

ResampleImage Normal002-MRA.mha --makeHighResIso Normal002-MRA-Iso.mha

Then use that as the template image for the ConvertTubesToImage command:

ConvertTubesToImage Normal002-MRA-Iso.mha VesselNetwork.tre VesselNetwork-Iso.mha

If there are still gaps, you can add in these commands to further upsample the image:

ResampleImage Normal002-MRA-Iso.mha --resampleFactor 2,2,2 Normal002-MRA-Iso2.mha ConvertTubesToImage Normal002-MRA-Iso2.mha VesselNetwork.tre VesselNetowrk-Iso2.mha

If that doesn't work, I can add an option to ConvertTubesToImage to specify a minimum radius to use. That way we can force every vessel to appear.

Fingers crossed, Stephen

On Tue, Aug 31, 2021 at 10:54 AM Subhashis Banerjee < @.***> wrote:

Thanks for the prompt reply.

I used the viewer https://paraview-medical.netlify.app/ for Normal002-MRA.

There are thin connections just like a vessel centerline in between a vessel. So that cannot be used as a segmentation.

A vessel then the diameter can vary but this is a kind of connection loss as appears.

I am attaching one screenshot and files that I have generated by ConvertTubesToImage. In the screenshot some of the disconnected or thin connected vessels are marked by yellow circles, there are many such. This is not a rendering issue as viewing differently generated the same result.

Please help me.

Thanks, Subhashis

[image: Screenshot 2021-08-31 20 07 42] https://user-images.githubusercontent.com/20064427/131525300-c846851b-159a-437f-aa7f-447760aa98f5.png Normal002-TRE.zip https://github.com/InsightSoftwareConsortium/ITKTubeTK/files/7084774/Normal002-TRE.zip VascularNetwork-002.zip https://github.com/InsightSoftwareConsortium/ITKTubeTK/files/7084776/VascularNetwork-002.zip

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/InsightSoftwareConsortium/ITKTubeTK/issues/81#issuecomment-909314015, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACEJLZ7K3TRW3PTPJ7TLOTT7TUL7ANCNFSM5DCS3C5Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

-- Stephen R. Aylward, Ph.D. Senior Director of Strategic Initiatives

Kitware: Delivering innovative, open source, scientific software.

Subhashis-Banerjee commented 3 years ago

Hi Stephen,

Thanks for the suggestion. Actually, I am using ITKTubeTK from jupyter notebook.

PixelType = itk.F Dimension = 3 ImageType = itk.Image[PixelType, Dimension]

Read tre file

TubeFileReaderType = itk.SpatialObjectReader[Dimension] tubeFileReader = TubeFileReaderType.New() tubeFileReader.SetFileName('VascularNetwork-002.tre') tubeFileReader.Update() tubes = tubeFileReader.GetGroup()

Read template image

TemplateImageType = itk.Image[PixelType, Dimension] TemplateImageReaderType = itk.ImageFileReader[TemplateImageType] templateImageReader = TemplateImageReaderType.New() templateImageReader.SetFileName('Normal002-MRA.mha') templateImageReader.Update() templateImage = templateImageReader.GetOutput()

Conversion

TubesToImageFilterType = ttk.ConvertTubesToImage[TemplateImageType] tubesToImageFilter = TubesToImageFilterType.New() tubesToImageFilter.SetUseRadius(True) tubesToImageFilter.SetTemplateImage(templateImageReader.GetOutput()) tubesToImageFilter.SetInput(tubes) tubesToImageFilter.Update()

Write

outputImage = tubesToImageFilter.GetOutput()
itk.imwrite(outputImage, 'converted.nii.gz')

Can you please suggest how to use the ResampleImage along with the code?

Or is there any other way?

Many thanks, Subhashis

aylward commented 3 years ago

...read the image and tubes as you do...and then...

Resample = ttk.ResampleImage.New(image) Resample.SetMakeHighResIso(True) Resample.Update() image_iso = Resample.GetOutput()

Render = ttk.ConvertTubesToImage[ImageReaderType].New() Render.SetInput(sampleSpatialObjectGroup) Render.SetTemplateImage(image_iso) Render.Update()

outputImage = Render.GetOutput()

itk.imwrite(outputImage, 'Normal002-TRE.mha')

On Tue, Aug 31, 2021 at 11:35 AM Subhashis Banerjee < @.***> wrote:

Hi Stephen,

Thanks for the suggestion. Actually, I am using ITKTubeTK from jupyter notebook.

Dimension = 3 PixelType = itk.F ImageReaderType = itk.ImageFileReader[ImageType]

imageReader = ImageReaderType.New() imageReader.SetFileName('Normal002-MRA.mha') imageReader.Update() image = imageReader.GetOutput()

TubeFileReaderType = itk.SpatialObjectReader[Dimension] tubeFileReader = TubeFileReaderType.New() tubeFileReader.SetFileName('VascularNetwork-002.tre') tubeFileReader.Update() sampleSpatialObjectGroup = tubeFileReader.GetGroup()

FilterType = ttk.ComputeTubeFlyThroughImage[PixelType, Dimension] Filter = FilterType.New() Filter.SetInputImage(image) Filter.SetTubeId(0) Filter.SetInput(sampleSpatialObjectGroup) # //Expected to work, but is not working Filter.Update()

outputImage = Filter.GetOutput()

itk.imwrite(outputImage, 'Normal002-TRE.mha')

Can you please suggest how to use the ResampleImage along with the code?

Or is there any other way?

Many thanks, Subhashis

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/InsightSoftwareConsortium/ITKTubeTK/issues/81#issuecomment-909348969, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACEJL74QGUFGQF73GM7YPDT7TZFZANCNFSM5DCS3C5Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

-- Stephen R. Aylward, Ph.D. Senior Director of Strategic Initiatives

Kitware: Delivering innovative, open source, scientific software.

Subhashis-Banerjee commented 3 years ago

Hi Stephen,

Thanks a lot for all your suggestions.

I tried as you suggested (images attached). Although HighResIso and resampleFactor 2,2,2 enhance the quality of the mask, still it is far from acceptable. As you can notice there are many discontinuities in vessels structures.

I check with many resampleFactors and visualization through other software but still, the issue is there.

Please suggest if anything can be done.

I really appreciate your support.

Thanks, Subhashis

1 2

aylward commented 3 years ago

Hi,

Ok, after you read in the tre file, can you please try:

SurfWriter = ttk.WriteTubesAsPolyData.New() SurfWriter.SetFileName("vesselsurface.vtp") SurfWriter.SetInput(sampleSpatialObjectGroup)

Then view the .vtp file in ParaView or using one of the links I previously sent. If that shows gaps, then the vessel file (the .tre file) must actually contain gaps.

s

On Fri, Sep 3, 2021 at 10:38 AM Subhashis Banerjee @.***> wrote:

Hi Stephen,

Thanks a lot for all your suggestions.

I tried as you suggested (images attached). Although HighResIso and resampleFactor 2,2,2 enhance the quality of the mask, still it is far from acceptable. As you can notice there are many discontinuities in vessels structures.

I check with many resampleFactors and visualization through other software but still, the issue is there.

Please suggest if anything can be done.

I really appreciate your support.

Thanks, Subhashis

[image: 1] https://user-images.githubusercontent.com/20064427/132023110-23fe8e73-ae4f-4e0c-b3be-996b9c290d3e.png [image: 2] https://user-images.githubusercontent.com/20064427/132023130-151db9c3-3960-4f13-87de-9078f1ff9207.png

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/InsightSoftwareConsortium/ITKTubeTK/issues/81#issuecomment-912588677, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACEJL7XQ7YBKHGJ63FLI73UADMVTANCNFSM5DCS3C5Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

-- Stephen R. Aylward, Ph.D. Senior Director of Strategic Initiatives

Kitware: Delivering innovative, open source, scientific software.

Subhashis-Banerjee commented 3 years ago

Hi,

Please find the attached ".vtp" file in ParaView. test

aylward commented 3 years ago

Great! No gaps!

Also, I just saw that you attached Normal002-TRE.mha. I just rendered it, and I don't see any gaps:

[image: image.png]

There are some really thin connections, but everything is connected. The thin connections are due to the discrete nature of the image data and the weakness of my width estimation algo.

You could write a script to replace every radius estimate with a local mean radius estimate - or set a minimum radius estimate etc.

s

On Fri, Sep 3, 2021 at 11:39 AM Subhashis Banerjee @.***> wrote:

Hi,

Please find the attached ".vtp" file in ParaView. [image: test] https://user-images.githubusercontent.com/20064427/132031832-2f84737e-3958-4d12-a074-ef174868598d.png

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/InsightSoftwareConsortium/ITKTubeTK/issues/81#issuecomment-912629578, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACEJLYPEJCQH24VD44RTULUADT3VANCNFSM5DCS3C5Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

-- Stephen R. Aylward, Ph.D. Senior Director of Strategic Initiatives

Kitware: Delivering innovative, open source, scientific software.

Subhashis-Banerjee commented 3 years ago

Okay Stephen, I'll try that, and if successful let you know.

Thanks for your effort and suggestions.

I really appreciate it. Subhashis