Example #1
0
 def test_adjust_gamma_zero(self):
     """White image should be returned for gamma equal to zero"""
     image = torch.FloatTensor(8, 8).uniform_(0, 255)
     result = adjust_gamma(image, 0)
     dtype = image.dtype
     self.assertTrue(
         torch.all(result == torch.tensor(dtype_range[dtype][1],
                                          dtype=result.dtype)))
Example #2
0
def adjust_gamma_demo():
    image = torch.tensor(data.astronaut())
    shift_left_img = adjust_gamma(image, 1.5)
    shift_right_img = adjust_gamma(image, 0.5)
    f, (ax1, ax2, ax3) = plt.subplots(1, 3)
    ax1.set_title("original image")
    ax1.get_xaxis().set_visible(False)
    ax1.get_yaxis().set_visible(False)
    ax1.imshow(image)
    ax2.set_title("adjust gamma 1.5")
    ax2.get_xaxis().set_visible(False)
    ax2.get_yaxis().set_visible(False)
    ax2.imshow(shift_left_img)
    ax3.set_title("adjust gamma 0.5")
    ax3.get_xaxis().set_visible(False)
    ax3.get_yaxis().set_visible(False)
    ax3.imshow(shift_right_img)
    f.show()
Example #3
0
    def test_adjust_gamma_greater_one(self):
        """Verifying the output with expected results for gamma
        correction with gamma equal to two"""
        image = torch.arange(0, 255, 4).reshape((8, 8)).type(torch.uint8)
        expected = torch.tensor(
            [[0, 0, 0, 0, 1, 1, 2, 3], [4, 5, 6, 7, 9, 10, 12, 14],
             [16, 18, 20, 22, 25, 27, 30, 33], [
                 36, 39, 42, 45, 49, 52, 56, 60
             ], [64, 68, 72, 76, 81, 85, 90, 95],
             [100, 105, 110, 116, 121, 127, 132, 138],
             [144, 150, 156, 163, 169, 176, 182, 189],
             [196, 203, 211, 218, 225, 233, 241, 249]],
            dtype=torch.uint8)

        result = adjust_gamma(image, 2)
        self.assertTrue(torch.equal(result, expected))
Example #4
0
    def test_adjust_gamma_less_one(self):
        """Verifying the output with expected results for gamma
        correction with gamma equal to half"""
        image = torch.arange(0, 255, 4).reshape((8, 8)).type(torch.uint8)
        expected = torch.tensor([[0, 31, 45, 55, 63, 71, 78, 84],
                                 [90, 95, 100, 105, 110, 115, 119, 123],
                                 [127, 131, 135, 139, 142, 146, 149, 153],
                                 [156, 159, 162, 165, 168, 171, 174, 177],
                                 [180, 183, 186, 188, 191, 194, 196, 199],
                                 [201, 204, 206, 209, 211, 214, 216, 218],
                                 [221, 223, 225, 228, 230, 232, 234, 236],
                                 [238, 241, 243, 245, 247, 249, 251, 253]],
                                dtype=torch.uint8)

        result = adjust_gamma(image, 0.5)
        self.assertTrue(torch.equal(result, expected))
Example #5
0
 def test_adjust_gamma_one(self):
     """Same image should be returned for gamma equal to one"""
     image = torch.FloatTensor(8, 8).uniform_(0, 255)
     result = adjust_gamma(image, 1)
     self.assertTrue(torch.equal(result, image))