def validate_orientation(dicoms):
    """
    Validate that all dicoms have the same orientation

    :param dicoms: list of dicoms
    """
    first_image_orient1 = numpy.array(dicoms[0].ImageOrientationPatient)[0:3]
    first_image_orient2 = numpy.array(dicoms[0].ImageOrientationPatient)[3:6]
    for dicom_ in dicoms:
        # Create affine matrix (http://nipy.sourceforge.net/nibabel/dicom/dicom_orientation.html#dicom-slice-affine)
        image_orient1 = numpy.array(dicom_.ImageOrientationPatient)[0:3]
        image_orient2 = numpy.array(dicom_.ImageOrientationPatient)[3:6]
        if not numpy.allclose(image_orient1, first_image_orient1, rtol=0.001, atol=0.001) \
                or not numpy.allclose(image_orient2, first_image_orient2, rtol=0.001, atol=0.001):
            logger.warning('Image orientations not consistent through all slices')
            logger.warning('---------------------------------------------------------')
            logger.warning('%s %s' % (image_orient1, first_image_orient1))
            logger.warning('%s %s' % (image_orient2, first_image_orient2))
            logger.warning('---------------------------------------------------------')
            raise ConversionValidationError('IMAGE_ORIENTATION_INCONSISTENT')
def validate_orientation ( dicoms ) : first_image_orient1 = numpy . array ( dicoms [ 0 ] . ImageOrientationPatient ) [ 0 : 3 ] first_image_orient2 = numpy . array ( dicoms [ 0 ] . ImageOrientationPatient ) [ 3 : 6 ] for dicom_ in dicoms : image_orient1 = numpy . array ( dicom_ . ImageOrientationPatient ) [ 0 : 3 ] image_orient2 = numpy . array ( dicom_ . ImageOrientationPatient ) [ 3 : 6 ] if not numpy . allclose ( image_orient1 , first_image_orient1 , rtol = 0.001 , atol = 0.001 ) or not numpy . allclose ( image_orient2 , first_image_orient2 , rtol = 0.001 , atol = 0.001 ) : logger . warning ( 'Image orientations not consistent through all slices' ) logger . warning ( '---------------------------------------------------------' ) logger . warning ( '%s %s' % ( image_orient1 , first_image_orient1 ) ) logger . warning ( '%s %s' % ( image_orient2 , first_image_orient2 ) ) logger . warning ( '---------------------------------------------------------' ) raise ConversionValidationError ( 'IMAGE_ORIENTATION_INCONSISTENT' )
Validate that all dicoms have the same orientation

    :param dicoms: list of dicoms