def test_cdf_match_lut(self): # Intensity values at 3,4,5,6 test_cdf = np.zeros((8)) test_cdf[3] = 0.25 test_cdf[4] = .5 test_cdf[5] = 0.75 test_cdf[6:] = 1.0 # Intensity values at 1,2,3,4 (test minus 2) match_cdf = np.zeros((8)) match_cdf[1] = 0.25 match_cdf[2] = .5 match_cdf[3] = 0.75 match_cdf[4:] = 1 logging.debug("match cdf: {}".format(match_cdf)) # Test all values are mapped down by 2 expected_lut = np.array([1, 1, 1, 1, 2, 3, 4, 4]) lut = hm.cdf_match_lut(test_cdf, match_cdf) np.testing.assert_array_equal(lut, expected_lut) # Intensity values all at 4 match_cdf = np.zeros((8)) match_cdf[4:] = 1 # Test all values are mapped to 4 expected_lut = np.array([4, 4, 4, 4, 4, 4, 4, 4]) lut = hm.cdf_match_lut(test_cdf, match_cdf) np.testing.assert_array_equal(lut, expected_lut) test_cdf = np.array([0, 9.99999881e-01]) match_cdf = np.array([0, 1]) self.assertRaises(hm.CDFException, hm.cdf_match_lut, test_cdf, match_cdf)
def test_cdf_match_lut(self): # Intensity values at 3,4,5,6 test_cdf = numpy.zeros((8)) test_cdf[3] = 0.25 test_cdf[4] = .5 test_cdf[5] = 0.75 test_cdf[6:] = 1.0 # Intensity values at 1,2,3,4 (test minus 2) match_cdf = numpy.zeros((8)) match_cdf[1] = 0.25 match_cdf[2] = .5 match_cdf[3] = 0.75 match_cdf[4:] = 1 logging.debug("match cdf: {}".format(match_cdf)) # Test all values are mapped down by 2 expected_lut = numpy.array([1, 1, 1, 1, 2, 3, 4, 4]) lut = hm.cdf_match_lut(test_cdf, match_cdf) numpy.testing.assert_array_equal(lut, expected_lut) # Intensity values all at 4 match_cdf = numpy.zeros((8)) match_cdf[4:] = 1 # Test all values are mapped to 4 expected_lut = numpy.array([4, 4, 4, 4, 4, 4, 4, 4]) lut = hm.cdf_match_lut(test_cdf, match_cdf) numpy.testing.assert_array_equal(lut, expected_lut) test_cdf = numpy.array([0, 9.99999881e-01]) match_cdf = numpy.array([0, 1]) self.assertRaises(hm.CDFException, hm.cdf_match_lut, test_cdf, match_cdf)
def test_cdf_normalization_band(self): for testno in ( 1, 2, ): input_bands, reference_bands, golden_lut = \ _get_test_data(testno) colors = ('Red', 'Green', 'Blue') for color in colors: in_band = input_bands[color] ref_band = reference_bands[color] print ref_band.min() print ref_band.max() in_cdf = colorimage.get_cdf(in_band) ref_cdf = colorimage.get_cdf(ref_band) color_lut = histogram_match.cdf_match_lut(in_cdf, ref_cdf) try: assert numpy.array_equal(color_lut, golden_lut[color]) except AssertionError: print "Got: {}".format(color_lut) print "Expected: {}".format(golden_lut[color]) raise Exception("Color {} for test data {} failed" \ .format(color, testno))
def test_cdf_normalization_band(self): for testno in (1,2,): input_bands, reference_bands, golden_lut = \ _get_test_data(testno) colors = ('Red', 'Green', 'Blue') for color in colors: in_band = input_bands[color] ref_band = reference_bands[color] in_cdf = colorimage.get_cdf(in_band) ref_cdf = colorimage.get_cdf(ref_band) color_lut = histogram_match.cdf_match_lut(in_cdf, ref_cdf) assert np.array_equal(color_lut, golden_lut[color])
def test_cdf_normalization_band(self): for testno in ( 1, 2, ): input_bands, reference_bands, golden_lut = \ _get_test_data(testno) colors = ('Red', 'Green', 'Blue') for color in colors: in_band = input_bands[color] ref_band = reference_bands[color] in_cdf = colorimage.get_cdf(in_band) ref_cdf = colorimage.get_cdf(ref_band) color_lut = histogram_match.cdf_match_lut(in_cdf, ref_cdf) assert np.array_equal(color_lut, golden_lut[color])
def test_cdf_normalization_band(self): for testno in (1,2,): input_bands, reference_bands, golden_lut = \ _get_test_data(testno) colors = ('Red', 'Green', 'Blue') for color in colors: in_band = input_bands[color] ref_band = reference_bands[color] print ref_band.min() print ref_band.max() in_cdf = colorimage.get_cdf(in_band) ref_cdf = colorimage.get_cdf(ref_band) color_lut = histogram_match.cdf_match_lut(in_cdf, ref_cdf) try: assert numpy.array_equal(color_lut, golden_lut[color]) except AssertionError: print "Got: {}".format(color_lut) print "Expected: {}".format(golden_lut[color]) raise Exception("Color {} for test data {} failed" \ .format(color, testno))