notmatthancock / pylidc

An object relational mapping for the LIDC dataset using sqlalchemy.
https://pylidc.github.io
Other
105 stars 40 forks source link

Remove contour points from mask #16

Closed notmatthancock closed 6 years ago

notmatthancock commented 6 years ago

@fedorov when you have the chance, can try your code from #15 out on the updated code from this branch to check if it resolves the issue? I've added some code to explicitly set the contour indexes to False in the boolean mask generation function.

fedorov commented 6 years ago

Unfortunately, this does not seem to resolve the problem. See below the screenshot, where the crosshairs is in the location of contour point, and it is toggled on in the left hand side, which corresponds to the mask produced by pylidc.

image

I think the info I provided in #15 should be sufficient to reproduce, but let me know if you have questions.

I am also wondering if special care should be taken for the exclusion contours. Assuming the definition for contour points is reversed, it would mean that for the exclusion contours contour points should not be erased.

fedorov commented 6 years ago

Never mind - it does seem to work! 🎆 - I forgot that I need to restart jupyter. image What I have not checked (and I need to think how to check that) is the exclusion contours. Do you think they need special consideration?

notmatthancock commented 6 years ago

Whether the region contained in the contour is marked as included or excluded, the contour points themselves are non-nodule. So, since in the exclusion loop, we turning off all image indexes either included in the exclusion contour or contained within that closed contour, I think that the code is correct.

If you'd like to check this, you can get an annotation with exclusion using, for example:

from pylidc import *
ann = query(Annotation).join(Contour).filter(Contour.inclusion == False).first()
fedorov commented 6 years ago

Sorry for the delay in follow up - it takes me time to wade through those things, and I was traveling.

Unfortunately, I don't think the referenced PR addresses the issue completely.

As you can see from the illustration below (subject LIDC-IDRI-0002, nodule MI014_11691 - the first one with exclusion contours), inclusion of the contours pixels for those contours that are marked with inclusion=False is inconsistent - some voxels are included in the mask, and some are not (for another exclusion contour inside the tumor volume, similar behavior is observed, so this is not due to the fact that exclusion contour abuts the lesion boundary). Green voxels are those of the lesion mask, blue points are inclusion contour, yellow - exclusion contour.

aug-01-2018 14-24-07

Masks used in visualization here, so you can reproduce in 3D Slicer.

Second issue, if we "reverse" the definition of the contour for the "exclusion" contour ("a complete contour of the nodule that describes the first voxel just outside the nodule"), I would think the contour points for the exclusion contour should be those that are "just inside the nodule". I will email TCIA to confirm this (if they know at all).

notmatthancock commented 6 years ago

@fedorov I've pushed a change to this branch that I believe takes care of your previous comment.

Regarding the include/exclude debate over points in exclusion contours:

Here is a relevant excerpt from the LIDC paper:

Each outline was meant to be a localizing “outer border” so that, in the opinion of the radiologist, the outline itself did not overlap pixels belonging to the nodule. The radiologists were able to explicitly outline regions of exclusion within a nodule (an air-filled cavity, for example), which were then recorded as such in the XML file

I interpret "outer border" as saying that the contours, being either inclusion or exclusion, should be outward to the nodule, with outward being in the sense of traveling in outward normal direction to the nodule. For inclusion contours this direction moves in increasing radial distance from the nodule, whereas in the the exclusion case, this direction moves in decreasing radial distance. And so, in both inclusion and exclusion contour cases, the contour points themselves should be excluded from the nodule.

Unfortunately, there are just the two of us; so, hopefully your email to TCIA can break the tie.

fedorov commented 6 years ago

Thank you, it seems to consistently exclude the contour points now (at least for the dataset I checked)!

Here is a relevant excerpt from the LIDC paper

Nice, I didn't explore that direction! Yes, I agree with you that based on that paragraph, the exclusion contour points should be excluded.

I suggest this PR is ready for merging - I think it is important to fix this, and the implementation is consistent, and is not in conflict with any of the documentation we have available.

đź‘Ť

notmatthancock commented 6 years ago

I appreciate your time spent helping to resolve this.

fedorov commented 6 years ago

đź‘Ť

I am glad I could help, and I thank you for the responsiveness and continuous maintenance of this project. I know it takes effort, and I want you to know I appreciate this!

fedorov commented 5 years ago

To close this particular question, I was able to get ultimate clarification on this issue from Sam Armato, who was one of the leads for the LIDC project, who confirmed our understanding was correct.

Andrey’s interpretation below is correct: exclude the points of the contour from the lesion voxels, whether contours are defined as inclusion or exclusion.

given the paragraph below from this paper (https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3041807/) the convention we followed in implementing the conversion was to exclude the points of the contour from the lesion voxels, whether contours are defined as inclusion or exclusion.

Hopefully our interpretation was correct!

"Each outline was meant to be a localizing “outer border” so that, in the opinion of the radiologist, the outline itself did not overlap pixels belonging to the nodule. The radiologists were able to explicitly outline regions of exclusion within a nodule (an air-filled cavity, for example), which were then recorded as such in the XML file”

notmatthancock commented 5 years ago

Great. I appreciate you following up on that and letting me know.