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

Function not found #13

Open
Naveenagv opened this issue Sep 8, 2021 · 1 comment
Open

Function not found #13

Naveenagv opened this issue Sep 8, 2021 · 1 comment

Comments

@Naveenagv
Copy link

I'm working on extracting the rtstruct co-ordinates of my file using the example in rtstruct.rst but :
from dicom_csv.rtstruct.csv import collect_rtstructs is not working. I have tried looking through the documentation and there is no function defining RTstruct. Please let me know of any ambiguities.

@kurmukovai
Copy link
Member

Hi, we temporarily remove this functionality, I am currently working on the updated (more general) version. Till then, you could use something like this to get the contours:

def read_contour_sequence(dataset: pydicom.dataset.Dataset) -> dict:
   
    contour_sequence_dict = dict()
    
    if not hasattr(dataset, 'ContourSequence'):
        raise AttributeError('Dataset does not have Contour Sequence.')
    
    for _slice in dataset.ContourSequence:
        key = _slice.ContourImageSequence[0].ReferencedSOPInstanceUID
        coords = np.array(_slice.ContourData)
        n = len(coords) // 3
        coords = coords.reshape((n, 3))
        if key not in contour_sequence_dict:
            contour_sequence_dict[key] = [coords]
        else:
            contour_sequence_dict[key].append(coords)
            
    return contour_sequence_dict

Usage example:

rtstruct = dcmread('path/to/rtstruct.dcm')
contours = list(rtstruct.ROIContourSequence)
contour_coords = read_contour_sequence(contours[0]) # if you have more than one contour in rtstruct you need to iterate over `contours`

contour_coords is a dictionary with keys being SOPInstanceUID of a reference image and values - coordinates of a contour. You might still need to postprocess them in case your image has non-unit ImageOrientationPatient and non-zero ImagePositionPatient fields.

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