tomdoel / pulmonarytoolkit

Lung medical image analysis and visualisation software for Matlab.
GNU General Public License v3.0
84 stars 57 forks source link

PTK viewer zoom #38

Open haribalankumar opened 4 years ago

haribalankumar commented 4 years ago

I used PTK to load up a scan recently. Its compressed Dicom images of ARDS patient. It loads fine on ITK-snap and 3D slicer. But PTK zooms it when imported and seems to crop out the image. Is there any setting i should change. Thanks.

tomdoel commented 4 years ago

Hi Hari,

PTK automatically crops the image to what it thinks is the lung region of interest (ROI). However, it determines this by segmenting the lung using an air threshold and region growing. If there's a lot of disease it may not detect the whole lung and will crop out too much.

You can switch PTK into "full image" display by selecting "Full Image" as the Context on the Plugins screen (in the codebase this is called the 'Original Image' Context).

Note this doesn't change the way any of the algorithms operate, it just shows the results on top of the full image rather than the cropped ROI. If the segmentation algorithms are failing, this won't fix them; it would need changes to the ROI detection algorithm (see PTKGetLungROIForCT.m).

haribalankumar commented 4 years ago

Thanks Tom, That issue is fixed!. When i segment the image and manually corrected them, i export them to jpeg files. As soon as I do that, the masks get cropped off at left and right boundary as seen in this snapshot. The exported masks also have this trimming. Not sure why this might happen.

PTK_edge_croppingissue
tomdoel commented 4 years ago

I think it's the same reason as before - the Lung Region of Interest (Lung ROI) is wrong. I don't think there's a simple solution in the UI - it would require some programming.

Lung segmentations (and any manual corrections to them) are cropped to the Lung ROI "Context" so if the Lung ROI misses out parts of the lung then the segmentations will be cropped too.

The Lung ROI is determined by the algorithm in PTKGetLungROIForCT.m (which calls PTKSegmentLungsWithoutClosing.m). It should include the whole lung region, but in this case it's not detecting all of the lung because of disease. You can in theory manually correct the LungROI (because you can manually correct any plugin result in PTK) but there is no tool for this in the UI so it would have to be done with the Matlab programming API.

So to fix it would require either:

a) modifying the above algorithm files to improve the ROI detection (note to stop PTK using previous cached results you need to increase the Version property in the PTKLungROI.m every time you modify the algorithms); or

b) applying a manual correction to the LungROI plugin results (this can't be done via the UI but could be done in Matlab but requires you to understand how to save manual corrections via the PTK API)

jakublaznovsky commented 4 years ago

Hello, I have encountered the same issue with the cropping image. I'd like to switch PTK into "full image" display mode, but in gui there is no button for that. I suppose that I need to switch PTK to developer mode, to see a Plugins screen. How can I do it, please? Thank you in advance.

tomdoel commented 4 years ago

Hi @jakublaznovsky. Developer mode is enabled by clicking the "Show dev tools" button on the toolbar at the bottom.

However, this won't fix your issue if you're planning to use any of the lung segmentation or analysis tools. PTK crops the image to the lung context, determined by the LungROI algorithm. So if the image is being cropped inside the lung boundary, it means the LungROI plugin does not work with your data. You'd need to modify or replace the LungROI algrorithm with your own that is designed for your data.

Switching to "full image" mode does not change the region used by the lung segmentation and analysis algorithms. All it does is display the results on the full image. The algorithms still operate on the LungROI context, so if that is wrong the algorithms may not produce the correct results.

haribalankumar commented 4 years ago

This is a quick fix:

  1. Run segment lung (segment tab lungs button)

  2. Correct the boundary and save edits

  3. Segment the lung again.

  4. Find PTKGetLungROIForCT.m comment line 47 which is reduced_image = PTKSegmentLungsWithoutClosing(reduced_image, false, true, false, reporting); Segment the lung again, manually correct the segment, save edits. and segment the lung

The 4th step skipped the cropping process and can save this mask from here. This is just a temporary fix I think - need to uncomment it back if you want to do other operations.