def test_get_cdf(self): test_band = np.array([ [0, 1], [2, 3] ], dtype=np.uint8) test_mask = np.array([ [False, True], [False, True] ], dtype=bool) # CDF goes up by 1/4 at 0, 1, 2, and 3 expected = np.ones(255) expected[0] = 0.25 expected[1] = 0.5 expected[2] = 0.75 cdf = colorimage.get_cdf(test_band) np.testing.assert_array_equal(cdf, expected) # 1 and 3 masked, so CDF goes up 1/2 at 0 and 2 expected = np.ones(255) expected[0] = 0.5 expected[1] = 0.5 cdf = colorimage.get_cdf(test_band, mask=test_mask) np.testing.assert_array_equal(expected, 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 cdf_normalization_luts(in_img, ref_img, in_mask=None, ref_mask=None, dtype=np.uint8): out_luts = [] height, width, bands = in_img.shape for bidx in range(bands): iband = in_img[:, :, bidx] rband = ref_img[:, :, bidx] in_cdf = ci.get_cdf(iband, mask=in_mask) ref_cdf = ci.get_cdf(rband, mask=ref_mask) lut = cdf_match_lut(in_cdf, ref_cdf, dtype=dtype) out_luts.append(lut) return out_luts
def cdf_normalization_luts(in_img, ref_img, in_mask=None, ref_mask=None, dtype=np.uint8): out_luts = [] height, width, bands = in_img.shape for bidx in range(bands): iband = in_img[:, :, bidx] rband = ref_img[:, :, bidx] in_cdf = ci.get_cdf(iband, mask=in_mask) ref_cdf = ci.get_cdf(rband, mask=ref_mask) #print bidx, in_cdf.sum(), ref_cdf.sum() lut = cdf_match_lut(in_cdf, ref_cdf, dtype=dtype) out_luts.append(lut) return out_luts
def test_get_cdf(self): test_band = numpy.array([[0, 1], [2, 3]], dtype=numpy.uint8) test_mask = numpy.array([[255, 0], [255, 0]], dtype=numpy.uint8) # CDF goes up by 1/4 at 0, 1, 2, and 3 expected = (.25) * numpy.ones((256)) expected[1] = .5 expected[2] = .75 expected[3:] = 1 cdf = colorimage.get_cdf(test_band) numpy.testing.assert_array_equal(cdf, expected) # 1 and 3 masked, so CDF goes up 1/2 at 0 and 2 expected = (.5) * numpy.ones((256)) expected[2:] = 1 cdf = colorimage.get_cdf(test_band, mask=test_mask) numpy.testing.assert_array_equal(cdf, expected)
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_get_cdf(self): test_band = np.array([[0, 1], [2, 3]], dtype=np.uint8) test_mask = np.array([[False, True], [False, True]], dtype=bool) # CDF goes up by 1/4 at 0, 1, 2, and 3 expected = np.ones(255) expected[0] = 0.25 expected[1] = 0.5 expected[2] = 0.75 cdf = colorimage.get_cdf(test_band) np.testing.assert_array_equal(cdf, expected) # 1 and 3 masked, so CDF goes up 1/2 at 0 and 2 expected = np.ones(255) expected[0] = 0.5 expected[1] = 0.5 cdf = colorimage.get_cdf(test_band, mask=test_mask) np.testing.assert_array_equal(expected, 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))