def __init__( self, graphic_type: Union[GraphicTypeValues, str], graphic_data: np.ndarray, source_image: SourceImageForRegion, pixel_origin_interpretation: Optional[ Union[PixelOriginInterpretationValues, str] ] = None ) -> None: """ Parameters ---------- graphic_type: Union[highdicom.sr.GraphicTypeValues, str] name of the graphic type graphic_data: numpy.ndarray array of ordered spatial coordinates, where each row of the array represents a (column, row) coordinate pair source_image: highdicom.sr.template.SourceImageForRegion source image to which `graphic_data` relates pixel_origin_interpretation: Union[highdicom.sr.PixelOriginInterpretationValues, str], optional whether pixel coordinates specified by `graphic_data` are defined relative to the total pixel matrix (``highdicom.sr.PixelOriginInterpretationValues.VOLUME``) or relative to an individual frame (``highdicom.sr.PixelOriginInterpretationValues.FRAME``) of the source image (default: ``highdicom.sr.PixelOriginInterpretationValues.VOLUME``) """ # noqa graphic_type = GraphicTypeValues(graphic_type) if graphic_type == GraphicTypeValues.MULTIPOINT: raise ValueError( 'Graphic type "MULTIPOINT" is not valid for region.' ) if not isinstance(source_image, SourceImageForRegion): raise TypeError( 'Argument "source_image" must have type SourceImageForRegion.' ) if pixel_origin_interpretation is None: pixel_origin_interpretation = PixelOriginInterpretationValues.VOLUME if pixel_origin_interpretation == PixelOriginInterpretationValues.FRAME: if (not hasattr(source_image, 'ReferencedFrameNumber') or source_image.ReferencedFrameNumber is None): raise ValueError( 'Frame number of source image must be specified when value ' 'of argument "pixel_origin_interpretation" is "FRAME".' ) super().__init__( name=CodedConcept( value='111030', meaning='Image Region', scheme_designator='DCM' ), graphic_type=graphic_type, graphic_data=graphic_data, pixel_origin_interpretation=pixel_origin_interpretation, relationship_type=RelationshipTypeValues.CONTAINS ) self.ContentSequence = [source_image]
def __init__( self, name: Union[Code, CodedConcept], graphic_type: Union[str, GraphicTypeValues], graphic_data: np.ndarray, pixel_origin_interpretation: Union[str, PixelOriginInterpretationValues], fiducial_uid: Optional[Union[str, UID]] = None, relationship_type: Optional[Union[str, RelationshipTypeValues]] = None ) -> None: """ Parameters ---------- name: Union[highdicom.sr.coding.CodedConcept, pydicom.sr.coding.Code] concept name graphic_type: Union[highdicom.sr.enum.GraphicTypeValues, str] name of the graphic type graphic_data: numpy.ndarray[numpy.int] array of ordered spatial coordinates, where each row of the array represents a (column, row) coordinate pair pixel_origin_interpretation: Union[highdicom.sr.enum.PixelOriginInterpretationValues, str] whether pixel coordinates specified by `graphic_data` are defined relative to the total pixel matrix (``highdicom.sr.enum.PixelOriginInterpretationValues.VOLUME``) or relative to an individual frame (``highdicom.sr.enum.PixelOriginInterpretationValues.FRAME``) fiducial_uid: Union[pydicom.uid.UID, str, None], optional unique identifier for the content item relationship_type: Union[highdicom.sr.enum.RelationshipTypeValues, str], optional type of relationship with parent content item """ # noqa super(ScoordContentItem, self).__init__(ValueTypeValues.SCOORD, name, relationship_type) graphic_type = GraphicTypeValues(graphic_type) pixel_origin_interpretation = PixelOriginInterpretationValues( pixel_origin_interpretation) self.GraphicType = graphic_type.value if graphic_type == GraphicTypeValues.POINT: if graphic_data.shape[0] != 1 or not graphic_data.shape[1] == 2: raise ValueError( 'Graphic data of a scoord of graphic type "POINT" ' 'must be a single (column row) pair in two-dimensional ' 'image coordinate space.') elif graphic_type == GraphicTypeValues.CIRCLE: if graphic_data.shape[0] != 2 or not graphic_data.shape[1] == 2: raise ValueError( 'Graphic data of a scoord of graphic type "CIRCLE" ' 'must be two (column, row) pairs in two-dimensional ' 'image coordinate space.') elif graphic_type == GraphicTypeValues.ELLIPSE: if graphic_data.shape[0] != 4 or not graphic_data.shape[1] == 2: raise ValueError( 'Graphic data of a scoord of graphic type "ELLIPSE" ' 'must be four (column, row) pairs in two-dimensional ' 'image coordinate space.') elif graphic_type == GraphicTypeValues.ELLIPSOID: if graphic_data.shape[0] != 6 or not graphic_data.shape[1] == 2: raise ValueError( 'Graphic data of a scoord of graphic type "ELLIPSOID" ' 'must be six (column, row) pairs in two-dimensional ' 'image coordinate space.') else: if not graphic_data.shape[0] > 1 or not graphic_data.shape[1] == 2: raise ValueError( 'Graphic data of a scoord must be multiple ' '(column, row) pairs in two-dimensional image ' 'coordinate space.') # Flatten list of coordinate pairs self.GraphicData = graphic_data.flatten().tolist() self.PixelOriginInterpretation = pixel_origin_interpretation.value if fiducial_uid is not None: self.FiducialUID = fiducial_uid