def test_alignment(self): """ Tests if the ImageSet info is correct except the image, as this is a little unpredictable """ rand_im = (np.random.rand(225, 225, 4) * 255).astype(np.uint8) rand_im[:, :, -1] = 1 input_im = np.zeros((4,) + rand_im.shape, dtype=np.uint8) for i in range(0, input_im.shape[0]): input_im[i] = rand_im input_im[1, :-2, :] = input_im[1, 2:, :] input_im[1, -3:, :] = 0 input_im[3] = np.rot90(input_im[3]) input_im_set = ImageSet(input_im) input_im_set.original_shape = input_im.shape[1:] input_im_set.shutter_speed = np.array([1, 2, 3, 4]) expected_im_set = ImageSet(input_im) # ignoring the returned image here expected_im_set.original_shape = (222, 222, 4) expected_im_set.shutter_speed = input_im_set.shutter_speed.copy() output_image_set = input_im_set.aligned_image_set() self.assertEqual(expected_im_set.original_shape, output_image_set.original_shape) self.assertTrue(np.array_equal(expected_im_set.shutter_speed, output_image_set.shutter_speed))
def random_image_set(x, y, colors, n): """ Creates a image set :param x: The width of the image :param y: The height of the image :param colors: IF the image needs colors :param n: The number of images :return: A ImageSet """ max_value = 255 rand_im = np.random.rand(x, y) exposure_im = np.zeros((n, x, y), dtype=int) if colors: rand_im = np.random.rand(x, y, 3) exposure_im = np.zeros((n, x, y, 3), dtype=int) rand_im = rand_im exposures = np.zeros(n) for i in range(1, n + 1): exposure_im[i - 1] = (rand_im * max_value * 2**(i - 1)).astype(int) exposure_im[i - 1][exposure_im[i - 1] > max_value] = max_value exposures[i - 1] = 2**(i - 1) im_set = ImageSet(exposure_im) im_set.shutter_speed = np.log(exposures) im_set.original_shape = rand_im.shape return rand_im, im_set
def test_gray_images(self): """ Tests ImageSet.gray_images() """ image = np.array([[[ # One image with shape (1, 3, 3) [1, 2, 3], [2, 3, 4], [100, 100, 100] ]]]) image_set = ImageSet(image) image_set.original_shape = (1, 3, 3) image_set.shutter_speed = [1] expected_image = np.array([[ # Shape (1, 3) 2, 3, 100 ]]).astype(float) output = image_set.gray_images() self.assertTrue(np.array_equal(output.images[0], expected_image))