MCPcopy Create free account
hub / github.com/VisionRush/DeepFakeDefenders / JPEGCompression

Class JPEGCompression

toolkit/dtransform.py:11–22  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9
10# 添加jpeg压缩
11class JPEGCompression:
12 def __init__(self, quality=10, p=0.3):
13 self.quality = quality
14 self.p = p
15
16 def __call__(self, img):
17 if np.random.rand() < self.p:
18 img_np = np.array(img)
19 _, buffer = cv2.imencode('.jpg', img_np[:, :, ::-1], [int(cv2.IMWRITE_JPEG_QUALITY), self.quality])
20 jpeg_img = cv2.imdecode(buffer, 1)
21 return Image.fromarray(jpeg_img[:, :, ::-1])
22 return img
23
24
25# 原始数据增强

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected