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

Class CQuantize

ram/utils/diffjpeg.py:178–205  ·  view source on GitHub ↗

JPEG Quantization for CbCr channels Args: rounding(function): rounding function to use

Source from the content-addressed store, hash-verified

176
177
178class CQuantize(nn.Module):
179 """ JPEG Quantization for CbCr channels
180
181 Args:
182 rounding(function): rounding function to use
183 """
184
185 def __init__(self, rounding):
186 super(CQuantize, self).__init__()
187 self.rounding = rounding
188 self.c_table = c_table
189
190 def forward(self, image, factor=1):
191 """
192 Args:
193 image(tensor): batch x height x width
194
195 Returns:
196 Tensor: batch x height x width
197 """
198 if isinstance(factor, (int, float)):
199 image = image.float() / (self.c_table * factor)
200 else:
201 b = factor.size(0)
202 table = self.c_table.expand(b, 1, 8, 8) * factor.view(b, 1, 1, 1)
203 image = image.float() / table
204 image = self.rounding(image)
205 return image
206
207
208class CompressJpeg(nn.Module):

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected