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

How to save segmentation results in NIFTI format #56

Open
Fiy-fly opened this issue Nov 29, 2022 · 2 comments
Open

How to save segmentation results in NIFTI format #56

Fiy-fly opened this issue Nov 29, 2022 · 2 comments

Comments

@Fiy-fly
Copy link

Fiy-fly commented Nov 29, 2022

Hello,I don‘t know How to save segmentation results in NIFTI format?
I use the “export segmentation ” at GUI ,then I get an RGB image in DICOM format.
I was wondering where I should find the original segmentation results in MATLAB.

@Fiy-fly
Copy link
Author

Fiy-fly commented Nov 29, 2022

Sorry,I already know how to save in NII format, but I'd still like to know how to see the raw segments in the MATLAB workspace

@tomdoel
Copy link
Owner

tomdoel commented Dec 5, 2022

Here are two ways:

  1. Using the GUI, you can "Export Segmentation" and choose "Format: Matlab". This should save the segmentation matrix as a Matlab .mat file, which you can load into the workspace. The segmentation matrix is of datatype uint8, where 0 means no segmented region, and other values mean part of a segmentation, where the values used depend on the type of segmentation. For example, for lung segmentations, 1 is Right and 2 is Left.

  2. You can write a script which uses the API (see Tutorial 3 for an introduction) and fetch the result of the corresponding segmentation plugin using dataset.GetResult(). The result will usualy be a PTKImage object, whose property RawImage is the Matlab matrix containing the segmentation values (same as above). NB be aware the segmentation image you get will be cropped to the lung region of interest by default - if you don't want this and want a full size image, then you would do this by adding an additional "context" argument set to PTKOriginalImage to the GetResult() call. For example dataset.GetResult('PTKLeftAndRightLungs', 'PTKOriginalImage');

Here is a rough example script for fetching lung and lobe segmentations using the API (Note I have not tested this!)

PTKAddPaths;
ptk_main = PTKMain();
uid = `PUT_THE_UID_FOR_YOUR_DATASET_HERE`;
dataset = ptk_main.CreateDatasetFromUid(uid);

lung_segmentation = dataset.GetResult('PTKLeftAndRightLungs');
% Now lung_segmentation.RawImage contains the lung segmentation matrix

lobe_segmentation = dataset.GetResult('PTKLobes');
% Now lobe_segmentation.RawImage contains the lobe segmentation matrix

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

No branches or pull requests

2 participants