MCPcopy Create free account
hub / github.com/XLearning-SCU/2022-CVPR-DART / __call__

Method __call__

ChannelAug.py:65–93  ·  view source on GitHub ↗
(self, img)

Source from the content-addressed store, hash-verified

63
64
65 def __call__(self, img):
66
67 # if random.uniform(0, 1) > self.probability:
68 # return img
69
70 idx = random.randint(0, 3)
71
72 if idx ==0:
73 # random select R Channel
74 img[1, :,:] = img[0,:,:]
75 img[2, :,:] = img[0,:,:]
76 elif idx ==1:
77 # random select B Channel
78 img[0, :,:] = img[1,:,:]
79 img[2, :,:] = img[1,:,:]
80 elif idx ==2:
81 # random select G Channel
82 img[0, :,:] = img[2,:,:]
83 img[1, :,:] = img[2,:,:]
84 else:
85 if random.uniform(0, 1) > self.probability:
86 # return img
87 img = img
88 else:
89 tmp_img = 0.2989 * img[0,:,:] + 0.5870 * img[1,:,:] + 0.1140 * img[2,:,:]
90 img[0,:,:] = tmp_img
91 img[1,:,:] = tmp_img
92 img[2,:,:] = tmp_img
93 return img
94
95class ChannelRandomErasing(object):
96 """ Randomly selects a rectangle region in an image and erases its pixels.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected