Пример #1
0
def compute_homography(image_filename, align_image_filename):
    try:
        # Convert images to grayscale if needed
        image = imread(image_filename, unchanged=True, anydepth=True)
        if image.shape[2] == 3:
            image_gray = to_8bit(cv2.cvtColor(image, cv2.COLOR_BGR2GRAY))
        else:
            image_gray = to_8bit(image[:,:,0])

        align_image = imread(align_image_filename, unchanged=True, anydepth=True)
        if align_image.shape[2] == 3:
            align_image_gray = to_8bit(cv2.cvtColor(align_image, cv2.COLOR_BGR2GRAY))
        else:
            align_image_gray = to_8bit(align_image[:,:,0])

        def compute_using(algorithm):
            h = algorithm(image_gray, align_image_gray)
            if h is None:
                return None, (None, None)

            det = np.linalg.det(h)
            
            # Check #1 homography's determinant will not be close to zero
            if abs(det) < 0.25:
                return None, (None, None)

            # Check #2 the ratio of the first-to-last singular value is sane (not too high)
            svd = np.linalg.svd(h, compute_uv=False)
            if svd[-1] == 0:
                return None, (None, None)
            
            ratio = svd[0] / svd[-1]
            if ratio > 100000:
                return None, (None, None)

            return h, (align_image_gray.shape[1], align_image_gray.shape[0])
        
        algo = 'feat'
        result = compute_using(find_features_homography)

        if result[0] is None:
            algo = 'ecc'
            log.ODM_INFO("Can't use features matching, will use ECC (this might take a bit)")
            result = compute_using(find_ecc_homography)
            if result[0] is None:
                algo = None
        
        warp_matrix, dimension = result
        return warp_matrix, dimension, algo

    except Exception as e:
        log.ODM_WARNING("Compute homography: %s" % str(e))
        return None, None, (None, None)
Пример #2
0
    def load_image(self, image, unchanged=False, anydepth=False):
        """Load image pixels as numpy array.

        The array is 3D, indexed by y-coord, x-coord, channel.
        The channels are in RGB order.
        """
        return io.imread(self._image_file(image), unchanged=unchanged, anydepth=anydepth)
Пример #3
0
    def load_image(self, image):
        """Load image pixels as numpy array.

        The array is 3D, indexed by y-coord, x-coord, channel.
        The channels are in RGB order.
        """
        return io.imread(self._image_file(image))
Пример #4
0
    def load_image(self, image):
        """Load image pixels as numpy array.

        The array is 3D, indexed by y-coord, x-coord, channel.
        The channels are in RGB order.
        """
        return io.imread(self._image_file(image))
Пример #5
0
 def load_segmentation(self, image):
     """Load image segmentation if it exists, otherwise return None."""
     segmentation_file = self._segmentation_file(image)
     if os.path.isfile(segmentation_file):
         segmentation = io.imread(segmentation_file, grayscale=True)
     else:
         segmentation = None
     return segmentation
Пример #6
0
 def load_instances(self, image: str) -> Optional[np.ndarray]:
     """Load image instances file if it exists, otherwise return None."""
     instances_file = self._instances_file(image)
     if os.path.isfile(instances_file):
         instances = io.imread(instances_file, grayscale=True)
     else:
         instances = None
     return instances
Пример #7
0
 def load_segmentation(self, image):
     """Load image segmentation if it exists, otherwise return None."""
     segmentation_file = self._segmentation_file(image)
     if os.path.isfile(segmentation_file):
         segmentation = io.imread(segmentation_file, grayscale=True)
     else:
         segmentation = None
     return segmentation
Пример #8
0
 def load_detection(self, image):
     """Load image detection if it exists, otherwise return None."""
     detection_file = self._detection_file(image)
     if os.path.isfile(detection_file):
         detection = io.imread(detection_file, grayscale=True)
     else:
         detection = None
     return detection
Пример #9
0
 def load_detection(self, image):
     """Load image detection if it exists, otherwise return None."""
     detection_file = self._detection_file(image)
     if os.path.isfile(detection_file):
         detection = io.imread(detection_file, grayscale=True)
     else:
         detection = None
     return detection
Пример #10
0
 def load_mask(self, image):
     """Load image mask if it exists, otherwise return None."""
     if image in self.mask_files:
         mask_path = self.mask_files[image]
         mask = io.imread(mask_path, grayscale=True)
         if mask is None:
             raise IOError("Unable to load mask for image {} "
                           "from file {}".format(image, mask_path))
     else:
         mask = None
     return mask
Пример #11
0
 def load_mask(self, image):
     """Load image mask if it exists, otherwise return None."""
     if image in self.mask_files:
         mask_path = self.mask_files[image]
         mask = io.imread(mask_path, grayscale=True)
         if mask is None:
             raise IOError("Unable to load mask for image {} "
                           "from file {}".format(image, mask_path))
     else:
         mask = None
     return mask
Пример #12
0
    def load_image(
        self,
        image: str,
        unchanged: bool = False,
        anydepth: bool = False,
        grayscale: bool = False,
    ) -> np.ndarray:
        """Load image pixels as numpy array.

        The array is 3D, indexed by y-coord, x-coord, channel.
        The channels are in RGB order.
        """
        return io.imread(
            self._image_file(image),
            unchanged=unchanged,
            anydepth=anydepth,
            grayscale=grayscale,
        )
Пример #13
0
 def load_undistorted_segmentation(self, image):
     """Load an undistorted image segmentation."""
     segmentation = io.imread(self._undistorted_segmentation_file(image),
                              grayscale=True)
     return segmentation
Пример #14
0
 def load_undistorted_detection(self, image):
     """Load an undistorted image detection."""
     detection = io.imread(self._undistorted_detection_file(image),
                           grayscale=True)
     return detection
Пример #15
0
 def load_undistorted_mask(self, image):
     """Load undistorted mask pixels as a numpy array."""
     return io.imread(self._undistorted_mask_file(image), grayscale=True)
Пример #16
0
 def load_undistorted_segmentation(self, image: str) -> np.ndarray:
     """Load an undistorted image segmentation."""
     return io.imread(self._undistorted_segmentation_file(image),
                      grayscale=True)
Пример #17
0
 def image_as_array(self, image):
     """Return image pixels as 3-dimensional numpy array (R G B order)"""
     return io.imread(self.__image_file(image))
Пример #18
0
 def image_as_array(self, image):
     """Return image pixels as 3-dimensional numpy array (R G B order)"""
     return io.imread(self.__image_file(image))
Пример #19
0
 def load_undistorted_detection(self, image):
     """Load an undistorted image detection."""
     detection = io.imread(self._undistorted_detection_file(image),
                           grayscale=True)
     return detection
Пример #20
0
 def load_undistorted_mask(self, image):
     """Load undistorted mask pixels as a numpy array."""
     return io.imread(self._undistorted_mask_file(image), grayscale=True)
Пример #21
0
 def undistorted_image_as_array(self, image):
     """Undistorted image pixels as 3-dimensional numpy array (R G B order)"""
     return io.imread(self._undistorted_image_file(image))
Пример #22
0
 def load_undistorted_image(self, image):
     """Load undistorted image pixels as a numpy array."""
     return io.imread(self._undistorted_image_file(image))
Пример #23
0
 def load_undistorted_image(self, image):
     """Load undistorted image pixels as a numpy array."""
     return io.imread(self._undistorted_image_file(image))
Пример #24
0
 def undistorted_image_as_array(self, image):
     """Undistorted image pixels as 3-dimensional numpy array (R G B order)"""
     return io.imread(self._undistorted_image_file(image))
Пример #25
0
 def load_undistorted_segmentation(self, image):
     """Load an undistorted image segmentation."""
     segmentation = io.imread(self._undistorted_segmentation_file(image),
                              grayscale=True)
     return segmentation