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

Class iDCT8x8

ram/utils/diffjpeg.py:297–321  ·  view source on GitHub ↗

Inverse discrete Cosine Transformation

Source from the content-addressed store, hash-verified

295
296
297class iDCT8x8(nn.Module):
298 """Inverse discrete Cosine Transformation
299 """
300
301 def __init__(self):
302 super(iDCT8x8, self).__init__()
303 alpha = np.array([1. / np.sqrt(2)] + [1] * 7)
304 self.alpha = nn.Parameter(torch.from_numpy(np.outer(alpha, alpha)).float())
305 tensor = np.zeros((8, 8, 8, 8), dtype=np.float32)
306 for x, y, u, v in itertools.product(range(8), repeat=4):
307 tensor[x, y, u, v] = np.cos((2 * u + 1) * x * np.pi / 16) * np.cos((2 * v + 1) * y * np.pi / 16)
308 self.tensor = nn.Parameter(torch.from_numpy(tensor).float())
309
310 def forward(self, image):
311 """
312 Args:
313 image(tensor): batch x height x width
314
315 Returns:
316 Tensor: batch x height x width
317 """
318 image = image * self.alpha
319 result = 0.25 * torch.tensordot(image, self.tensor, dims=2) + 128
320 result.view(image.shape)
321 return result
322
323
324class BlockMerging(nn.Module):

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected