Пример #1
0
    def test_identity_filter_grey(self):
        '''
	Tests whether the cross-correlation identity returns the original image
	'''
        identity = np.zeros((3, 3))
        identity[1, 1] = 1
        img_dup = hybrid.cross_correlation_2d(self.small_img_grey, identity)
        self.assertTrue(np.allclose(img_dup, self.small_img_grey, atol=1e-08), \
         msg="Failed to return original image under identity cross-correlation")
Пример #2
0
    def test_mean_filter_RGB(self):
	'''
	Tests cross-correlation of RGB image using a rectangular filter
	'''
	mean = np.ones((3,3))
	student = hybrid.cross_correlation_2d(self.img_rgb, mean)
	solution = cv2.filter2D(self.img_rgb, -1, mean, borderType=cv2.BORDER_CONSTANT)

	self.assertTrue(np.allclose(student, solution, atol=1e-08), \
		msg="Incorrect cross-correlation of RGB image using mean filter")
Пример #3
0
    def test_rand_rect_filter_RGB(self):
	'''
	Tests cross-correlation of RGB image using a random rectangular filter
	'''
	rand_filt = np.random.rand(5,7)
	student = hybrid.cross_correlation_2d(self.img_rgb, rand_filt)
	solution = cv2.filter2D(self.img_rgb, -1, rand_filt, borderType=cv2.BORDER_CONSTANT)

	self.assertTrue(np.allclose(student, solution, atol=1e-08), \
		msg="Incorrect cross-correlation of RGB image using random rectangular filter")
Пример #4
0
    def test_mean_filter_rect_grey(self):
	'''
	Tests cross-correlation of greyscale image using a rectangular mean filter
	'''
	mean = np.ones((3,5))
	student = hybrid.cross_correlation_2d(self.small_img_grey, mean)
	solution = cv2.filter2D(self.small_img_grey, -1, mean, borderType=cv2.BORDER_CONSTANT)

	self.assertTrue(np.allclose(student, solution, atol=1e-08), \
		msg="Incorrect cross-correlation of greyscale image using rectangular mean filter")
Пример #5
0
    def test_big_filter_grey(self):
	'''
	Tests cross-correlation of greyscale image using a filter bigger than image
	'''
	filter_height = self.small_height % 2 + self.small_height + 1
	filter_width = self.small_width % 2 + self.small_width + 1
	rand_filter = np.random.rand(filter_height, filter_width)
	student = hybrid.cross_correlation_2d(self.small_img_grey, rand_filter)
	solution = cv2.filter2D(self.small_img_grey, -1, rand_filter, borderType=cv2.BORDER_CONSTANT)

	self.assertTrue(np.allclose(student, solution, atol=1e-08), \
		msg="Incorrect cross-correlation of greyscale image using filter bigger than image")