Contour

class pylidc.Contour(**kwargs)[source]

The Contour class holds the nodule boundary coordinate data of a pylidc.Annotation object for a single slice in the CT volume.

inclusion

bool – If True, the area inside the contour is included as part of the nodule. If False, the area inside the contour is excluded from the nodule.

image_z_position

float – This is the imageZposition defined via the xml annnotations for this contour. It is the z-coordinate of DICOM attribute (0020,0032).

dicom_file_name

string – This is the name of the corresponding DICOM file for the scan to which this contour belongs, having the same image_z_position.

coords

string – These are the sequential (x,y) coordinates of the curve, stored as a string. It is better to access these coordinates using the to_matrix method, which returns a numpy array rather than a string.

Example

Plotting a contour on top of the image volume:

import pylidc as pl
import matplotlib.pyplot as plt

ann = pl.query(pl.Annotation).first()
vol = ann.scan.to_volume()
con = ann.contours[3]

k = con.image_k_position
ii,jj = ann.contours[3].to_matrix(include_k=False).T

plt.imshow(vol[:,:,46], cmap=plt.cm.gray)
plt.plot(jj, ii, '-r', lw=1, label="Nodule Boundary")
plt.legend()
plt.show()
image_k_position

Similar to Contour.image_z_position, but returns the index instead of the z coordinate value.

Note

This index may not be unique if the slice_zvals of the respective scan are not unique.

to_matrix(include_k=True)[source]

Return the contour-annotation coordinates as a matrix where each row contains an (i,j,k) index coordinate into the image volume.

Parameters:include_k (bool, default=True) – Set include_k=False to omit the k axis coordinate.