MCPcopy Create free account
hub / github.com/DragonisCV/RAM / YCbCr2RGBJpeg

Class YCbCr2RGBJpeg

ram/utils/diffjpeg.py:378–398  ·  view source on GitHub ↗

Converts YCbCr image to RGB JPEG

Source from the content-addressed store, hash-verified

376
377
378class 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
401class DeCompressJpeg(nn.Module):

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected