示例#1
0
def image_distances(distance_function, image1, image2):
    '''Measures the distance between the histogram of corresponding bands in
    two images. '''
    bands1 = cv2.split(image1)
    bands2 = cv2.split(image2)
    assert len(bands1) == len(bands2)
    dist = []
    for band1, band2 in zip(bands1, bands2):
        dist.append(distance_function(
            ci.get_histogram(band1), ci.get_histogram(band2)))
    return dist
示例#2
0
    def test_get_histogram(self):
        test_band = numpy.array([[1, 1], [1, 1]], dtype=numpy.uint8)
        test_mask = numpy.array([[255, 0], [255, 0]], dtype=numpy.uint8)

        # All entries at intensity 1
        expected = numpy.zeros((256), dtype=numpy.int)
        expected[1] = 4
        hist = colorimage.get_histogram(test_band)
        numpy.testing.assert_array_equal(hist, expected)

        # Two values masked, count should drop by two
        expected = numpy.zeros((256), dtype=numpy.int)
        expected[1] = 2
        hist = colorimage.get_histogram(test_band, mask=test_mask)
        numpy.testing.assert_array_equal(hist, expected)
示例#3
0
    def test_get_histogram(self):
        test_band = numpy.array([[1, 1], [1, 1]], dtype=numpy.uint8)
        test_mask = numpy.array([[255, 0], [255, 0]], dtype=numpy.uint8)

        # All entries at intensity 1
        expected = numpy.zeros((256), dtype=numpy.int)
        expected[1] = 4
        hist = colorimage.get_histogram(test_band)
        numpy.testing.assert_array_equal(hist, expected)

        # Two values masked, count should drop by two
        expected = numpy.zeros((256), dtype=numpy.int)
        expected[1] = 2
        hist = colorimage.get_histogram(test_band, mask=test_mask)
        numpy.testing.assert_array_equal(hist, expected)
def image_distances(distance_function, image1, image2):
    """
    Measures the distance between the histogram of corresponding bands in
    two images.
    """

    shape1 = image1.shape
    shape2 = image2.shape

    assert shape1[2] == shape2[2]

    bands1 = [image1[:, :, bidx] for bidx in range(shape1[2])]
    bands2 = [image2[:, :, bidx] for bidx in range(shape2[2])]

    dist = []
    for band1, band2 in zip(bands1, bands2):
        dist.append(distance_function(ci.get_histogram(band1), ci.get_histogram(band2)))
    return dist
def image_distances(distance_function, image1, image2):
    """
    Measures the distance between the histogram of corresponding bands in
    two images.
    """
    
    shape1 = image1.shape
    shape2 = image2.shape
    
    assert shape1[2] == shape2[2]
    
    bands1 = [ image1[:, :, bidx] for bidx in range(shape1[2]) ]
    bands2 = [ image2[:, :, bidx] for bidx in range(shape2[2]) ]

    dist = []
    for band1, band2 in zip(bands1, bands2):
        dist.append(distance_function(
            ci.get_histogram(band1), ci.get_histogram(band2)))
    return dist
示例#6
0
    def test_get_histogram(self):

        test_band = np.array([
            [1, 1],
            [1, 1]
        ], dtype=np.uint8)
        test_mask = np.array([
            [255, 0],
            [255, 0]
        ], dtype=np.uint8)

        # All entries at intensity 1
        expected = np.zeros(255, dtype=np.int)
        expected[1] = 4
        hist = colorimage.get_histogram(test_band)
        np.testing.assert_array_equal(hist, expected)

        expected = np.zeros(255, dtype=np.int)
        expected[1] = 2
        hist = colorimage.get_histogram(test_band, mask=test_mask)
        np.testing.assert_array_equal(hist, expected)

        test_band = np.array([
            [0, 1],
            [2, 3]
        ], dtype=np.uint8)
        test_mask = np.array([
            [False, True],
            [False, True]
        ], dtype=bool)
        expected = np.zeros(255, dtype=np.int)
        expected[0] = 1
        expected[2] = 1

        hist = colorimage.get_histogram(test_band, mask=test_mask)
        np.testing.assert_array_equal(expected, hist)
    def test_get_histogram(self):

        test_band = np.array([[1, 1], [1, 1]], dtype=np.uint8)
        test_mask = np.array([[255, 0], [255, 0]], dtype=np.uint8)

        # All entries at intensity 1
        expected = np.zeros(255, dtype=np.int)
        expected[1] = 4
        hist = colorimage.get_histogram(test_band)
        np.testing.assert_array_equal(hist, expected)

        expected = np.zeros(255, dtype=np.int)
        expected[1] = 2
        hist = colorimage.get_histogram(test_band, mask=test_mask)
        np.testing.assert_array_equal(hist, expected)

        test_band = np.array([[0, 1], [2, 3]], dtype=np.uint8)
        test_mask = np.array([[False, True], [False, True]], dtype=bool)
        expected = np.zeros(255, dtype=np.int)
        expected[0] = 1
        expected[2] = 1

        hist = colorimage.get_histogram(test_band, mask=test_mask)
        np.testing.assert_array_equal(expected, hist)