Converts YCbCr image to RGB JPEG
| 376 | |
| 377 | |
| 378 | class YCbCr2RGBJpeg(nn.Module): |
| 379 | """Converts YCbCr image to RGB JPEG |
| 380 | """ |
| 381 | |
| 382 | def __init__(self): |
| 383 | super(YCbCr2RGBJpeg, self).__init__() |
| 384 | |
| 385 | matrix = np.array([[1., 0., 1.402], [1, -0.344136, -0.714136], [1, 1.772, 0]], dtype=np.float32).T |
| 386 | self.shift = nn.Parameter(torch.tensor([0, -128., -128.])) |
| 387 | self.matrix = nn.Parameter(torch.from_numpy(matrix)) |
| 388 | |
| 389 | def forward(self, image): |
| 390 | """ |
| 391 | Args: |
| 392 | image(tensor): batch x height x width x 3 |
| 393 | |
| 394 | Returns: |
| 395 | Tensor: batch x 3 x height x width |
| 396 | """ |
| 397 | result = torch.tensordot(image + self.shift, self.matrix, dims=1) |
| 398 | return result.view(image.shape).permute(0, 3, 1, 2) |
| 399 | |
| 400 | |
| 401 | class DeCompressJpeg(nn.Module): |