Python cv2.COLOR_BGR2BGRA Examples
The following are 11
code examples of cv2.COLOR_BGR2BGRA().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
cv2
, or try the search function
.
Example #1
Source File: engine_cv3.py From opencv-engine with MIT License | 5 votes |
def enable_alpha(self): if self.image_channels < 4: with_alpha = np.zeros((self.size[1], self.size[0], 4), self.image.dtype) if self.image_channels == 3: cv2.cvtColor(self.image, cv2.COLOR_BGR2BGRA, with_alpha) else: cv2.cvtColor(self.image, cv2.COLOR_GRAY2BGRA, with_alpha) self.image = with_alpha
Example #2
Source File: utils.py From ad-versarial with MIT License | 5 votes |
def to_alpha(logo): if has_alpha(logo): return logo if is_gray(logo): return cv2.cvtColor(logo, cv2.COLOR_GRAY2BGRA) else: return cv2.cvtColor(logo, cv2.COLOR_BGR2BGRA)
Example #3
Source File: EnStrToPng.py From Hidden-Eye with GNU General Public License v3.0 | 5 votes |
def HideStringIntoPng_8bit1pixel(img,DataArray,seed = 0): # saving points where data is hidden DataHidenX = [] DataHidenY = [] DataHidenXY = [] if(seed != 0): rd.seed(seed) h , w, c = img.shape if c <= 3: img = cv2.cvtColor(img,cv2.COLOR_BGR2BGRA) # hiding data into image counter = len(DataArray) i = 0 while i < counter: x = rd.randint(0,h -1) y = rd.randint(0,w - 1) while (x,y) in DataHidenXY: x = rd.randint(0,h -1) y = rd.randint(0,w - 1) DataHidenXY.append((x,y)) DataHidenX.append(x) DataHidenY.append(y) img[x][y][0] |= 0x03 img[x][y][0] &= (0xfc | DataArray[i]) img[x][y][1] |= 0x03 img[x][y][1] &= (0xfc | DataArray[i + 1]) img[x][y][2] |= 0x03 img[x][y][2] &= (0xfc | DataArray[i + 2]) img[x][y][3] |= 0x03 img[x][y][3] &= (0xfc | DataArray[i + 3]) i += 4 return DataHidenX,DataHidenY,img
Example #4
Source File: EnPdfToPng.py From Hidden-Eye with GNU General Public License v3.0 | 5 votes |
def HidePdfintoPng(img,DataArray,seed = 0): # saving points where data is hidden if(seed != 0): rd.seed(seed) h , w, c = img.shape if c <= 3: img = cv2.cvtColor(img,cv2.COLOR_BGR2BGRA) # hiding data into image counter = len(DataArray) print (counter) i = 0 x = 0 y = 0 while i < counter: #print (i) img[x][y][0] |= 0x03 img[x][y][0] &= (0xfc | DataArray[i]) img[x][y][1] |= 0x03 img[x][y][1] &= (0xfc | DataArray[i + 1]) img[x][y][2] |= 0x03 img[x][y][2] &= (0xfc | DataArray[i + 2]) img[x][y][3] |= 0x03 img[x][y][3] &= (0xfc | DataArray[i + 3]) i += 4 if(x == h -1): break if(y == w -1): x += 1 y = 0 y += 1 return x,y-1,img
Example #5
Source File: gui.py From PUBGIS with GNU General Public License v3.0 | 5 votes |
def __init__(self, parent, minimap_iterator, output_file, output_flags): super(PUBGISWorkerThread, self).__init__(parent) self.parent = parent self.minimap_iterator = minimap_iterator self.output_file = output_file self.full_positions = [] self.timestamps = [] self.base_map_alpha = cv2.cvtColor(PUBGISMatch.full_map, cv2.COLOR_BGR2BGRA) self.preview_map = cv2.cvtColor(PUBGISMatch.full_map, cv2.COLOR_BGR2BGRA) self.output_flags = output_flags
Example #6
Source File: image.py From surface-crack-detection with MIT License | 5 votes |
def overlay(image, layer): if (len(layer.shape) == 2): layer = cv2.cvtColor(layer, cv2.COLOR_GRAY2BGR) image = cv2.cvtColor(image, cv2.COLOR_BGR2BGRA) layer = cv2.cvtColor(layer, cv2.COLOR_BGR2BGRA) layer[np.where((layer == [0,0,0,255]).all(axis=2))] = const.BACKGROUND_COLOR + [255] layer[np.where((layer == [255,255,255,255]).all(axis=2))] = const.SEGMENTATION_COLOR + [255] layer = cv2.addWeighted(image, 0.6, layer, 0.4, 0) return layer
Example #7
Source File: corruptions.py From robustness with Apache License 2.0 | 4 votes |
def spatter(x, severity=1): c = [(0.65, 0.3, 4, 0.69, 0.6, 0), (0.65, 0.3, 3, 0.68, 0.6, 0), (0.65, 0.3, 2, 0.68, 0.5, 0), (0.65, 0.3, 1, 0.65, 1.5, 1), (0.67, 0.4, 1, 0.65, 1.5, 1)][severity - 1] x = np.array(x, dtype=np.float32) / 255. liquid_layer = np.random.normal(size=x.shape[:2], loc=c[0], scale=c[1]) liquid_layer = gaussian(liquid_layer, sigma=c[2]) liquid_layer[liquid_layer < c[3]] = 0 if c[5] == 0: liquid_layer = (liquid_layer * 255).astype(np.uint8) dist = 255 - cv2.Canny(liquid_layer, 50, 150) dist = cv2.distanceTransform(dist, cv2.DIST_L2, 5) _, dist = cv2.threshold(dist, 20, 20, cv2.THRESH_TRUNC) dist = cv2.blur(dist, (3, 3)).astype(np.uint8) dist = cv2.equalizeHist(dist) ker = np.array([[-2, -1, 0], [-1, 1, 1], [0, 1, 2]]) dist = cv2.filter2D(dist, cv2.CV_8U, ker) dist = cv2.blur(dist, (3, 3)).astype(np.float32) m = cv2.cvtColor(liquid_layer * dist, cv2.COLOR_GRAY2BGRA) m /= np.max(m, axis=(0, 1)) m *= c[4] # water is pale turqouise color = np.concatenate((175 / 255. * np.ones_like(m[..., :1]), 238 / 255. * np.ones_like(m[..., :1]), 238 / 255. * np.ones_like(m[..., :1])), axis=2) color = cv2.cvtColor(color, cv2.COLOR_BGR2BGRA) x = cv2.cvtColor(x, cv2.COLOR_BGR2BGRA) return cv2.cvtColor(np.clip(x + m * color, 0, 1), cv2.COLOR_BGRA2BGR) * 255 else: m = np.where(liquid_layer > c[3], 1, 0) m = gaussian(m.astype(np.float32), sigma=c[4]) m[m < 0.8] = 0 # mud brown color = np.concatenate((63 / 255. * np.ones_like(x[..., :1]), 42 / 255. * np.ones_like(x[..., :1]), 20 / 255. * np.ones_like(x[..., :1])), axis=2) color *= m[..., np.newaxis] x *= (1 - m[..., np.newaxis]) return np.clip(x + color, 0, 1) * 255
Example #8
Source File: make_imagenet_c.py From robustness with Apache License 2.0 | 4 votes |
def spatter(x, severity=1): c = [(0.65, 0.3, 4, 0.69, 0.6, 0), (0.65, 0.3, 3, 0.68, 0.6, 0), (0.65, 0.3, 2, 0.68, 0.5, 0), (0.65, 0.3, 1, 0.65, 1.5, 1), (0.67, 0.4, 1, 0.65, 1.5, 1)][severity - 1] x = np.array(x, dtype=np.float32) / 255. liquid_layer = np.random.normal(size=x.shape[:2], loc=c[0], scale=c[1]) liquid_layer = gaussian(liquid_layer, sigma=c[2]) liquid_layer[liquid_layer < c[3]] = 0 if c[5] == 0: liquid_layer = (liquid_layer * 255).astype(np.uint8) dist = 255 - cv2.Canny(liquid_layer, 50, 150) dist = cv2.distanceTransform(dist, cv2.DIST_L2, 5) _, dist = cv2.threshold(dist, 20, 20, cv2.THRESH_TRUNC) dist = cv2.blur(dist, (3, 3)).astype(np.uint8) dist = cv2.equalizeHist(dist) # ker = np.array([[-1,-2,-3],[-2,0,0],[-3,0,1]], dtype=np.float32) # ker -= np.mean(ker) ker = np.array([[-2, -1, 0], [-1, 1, 1], [0, 1, 2]]) dist = cv2.filter2D(dist, cv2.CV_8U, ker) dist = cv2.blur(dist, (3, 3)).astype(np.float32) m = cv2.cvtColor(liquid_layer * dist, cv2.COLOR_GRAY2BGRA) m /= np.max(m, axis=(0, 1)) m *= c[4] # water is pale turqouise color = np.concatenate((175 / 255. * np.ones_like(m[..., :1]), 238 / 255. * np.ones_like(m[..., :1]), 238 / 255. * np.ones_like(m[..., :1])), axis=2) color = cv2.cvtColor(color, cv2.COLOR_BGR2BGRA) x = cv2.cvtColor(x, cv2.COLOR_BGR2BGRA) return cv2.cvtColor(np.clip(x + m * color, 0, 1), cv2.COLOR_BGRA2BGR) * 255 else: m = np.where(liquid_layer > c[3], 1, 0) m = gaussian(m.astype(np.float32), sigma=c[4]) m[m < 0.8] = 0 # m = np.abs(m) ** (1/c[4]) # mud brown color = np.concatenate((63 / 255. * np.ones_like(x[..., :1]), 42 / 255. * np.ones_like(x[..., :1]), 20 / 255. * np.ones_like(x[..., :1])), axis=2) color *= m[..., np.newaxis] x *= (1 - m[..., np.newaxis]) return np.clip(x + color, 0, 1) * 255
Example #9
Source File: make_cifar_c.py From robustness with Apache License 2.0 | 4 votes |
def spatter(x, severity=1): c = [(0.62,0.1,0.7,0.7,0.5,0), (0.65,0.1,0.8,0.7,0.5,0), (0.65,0.3,1,0.69,0.5,0), (0.65,0.1,0.7,0.69,0.6,1), (0.65,0.1,0.5,0.68,0.6,1)][severity - 1] x = np.array(x, dtype=np.float32) / 255. liquid_layer = np.random.normal(size=x.shape[:2], loc=c[0], scale=c[1]) liquid_layer = gaussian(liquid_layer, sigma=c[2]) liquid_layer[liquid_layer < c[3]] = 0 if c[5] == 0: liquid_layer = (liquid_layer * 255).astype(np.uint8) dist = 255 - cv2.Canny(liquid_layer, 50, 150) dist = cv2.distanceTransform(dist, cv2.DIST_L2, 5) _, dist = cv2.threshold(dist, 20, 20, cv2.THRESH_TRUNC) dist = cv2.blur(dist, (3, 3)).astype(np.uint8) dist = cv2.equalizeHist(dist) # ker = np.array([[-1,-2,-3],[-2,0,0],[-3,0,1]], dtype=np.float32) # ker -= np.mean(ker) ker = np.array([[-2, -1, 0], [-1, 1, 1], [0, 1, 2]]) dist = cv2.filter2D(dist, cv2.CV_8U, ker) dist = cv2.blur(dist, (3, 3)).astype(np.float32) m = cv2.cvtColor(liquid_layer * dist, cv2.COLOR_GRAY2BGRA) m /= np.max(m, axis=(0, 1)) m *= c[4] # water is pale turqouise color = np.concatenate((175 / 255. * np.ones_like(m[..., :1]), 238 / 255. * np.ones_like(m[..., :1]), 238 / 255. * np.ones_like(m[..., :1])), axis=2) color = cv2.cvtColor(color, cv2.COLOR_BGR2BGRA) x = cv2.cvtColor(x, cv2.COLOR_BGR2BGRA) return cv2.cvtColor(np.clip(x + m * color, 0, 1), cv2.COLOR_BGRA2BGR) * 255 else: m = np.where(liquid_layer > c[3], 1, 0) m = gaussian(m.astype(np.float32), sigma=c[4]) m[m < 0.8] = 0 # m = np.abs(m) ** (1/c[4]) # mud brown color = np.concatenate((63 / 255. * np.ones_like(x[..., :1]), 42 / 255. * np.ones_like(x[..., :1]), 20 / 255. * np.ones_like(x[..., :1])), axis=2) color *= m[..., np.newaxis] x *= (1 - m[..., np.newaxis]) return np.clip(x + color, 0, 1) * 255
Example #10
Source File: make_tinyimagenet_c.py From robustness with Apache License 2.0 | 4 votes |
def spatter(x, severity=1): c = [(0.62,0.1,0.7,0.7,0.6,0), (0.65,0.1,0.8,0.7,0.6,0), (0.65,0.3,1,0.69,0.6,0), (0.65,0.1,0.7,0.68,0.6,1), (0.65,0.1,0.5,0.67,0.6,1)][severity - 1] x = np.array(x, dtype=np.float32) / 255. liquid_layer = np.random.normal(size=x.shape[:2], loc=c[0], scale=c[1]) liquid_layer = gaussian(liquid_layer, sigma=c[2]) liquid_layer[liquid_layer < c[3]] = 0 if c[5] == 0: liquid_layer = (liquid_layer * 255).astype(np.uint8) dist = 255 - cv2.Canny(liquid_layer, 50, 150) dist = cv2.distanceTransform(dist, cv2.DIST_L2, 5) _, dist = cv2.threshold(dist, 20, 20, cv2.THRESH_TRUNC) dist = cv2.blur(dist, (3, 3)).astype(np.uint8) dist = cv2.equalizeHist(dist) # ker = np.array([[-1,-2,-3],[-2,0,0],[-3,0,1]], dtype=np.float32) # ker -= np.mean(ker) ker = np.array([[-2, -1, 0], [-1, 1, 1], [0, 1, 2]]) dist = cv2.filter2D(dist, cv2.CV_8U, ker) dist = cv2.blur(dist, (3, 3)).astype(np.float32) m = cv2.cvtColor(liquid_layer * dist, cv2.COLOR_GRAY2BGRA) m /= np.max(m, axis=(0, 1)) m *= c[4] # water is pale turqouise color = np.concatenate((175 / 255. * np.ones_like(m[..., :1]), 238 / 255. * np.ones_like(m[..., :1]), 238 / 255. * np.ones_like(m[..., :1])), axis=2) color = cv2.cvtColor(color, cv2.COLOR_BGR2BGRA) x = cv2.cvtColor(x, cv2.COLOR_BGR2BGRA) return cv2.cvtColor(np.clip(x + m * color, 0, 1), cv2.COLOR_BGRA2BGR) * 255 else: m = np.where(liquid_layer > c[3], 1, 0) m = gaussian(m.astype(np.float32), sigma=c[4]) m[m < 0.8] = 0 # m = np.abs(m) ** (1/c[4]) # mud brown color = np.concatenate((63 / 255. * np.ones_like(x[..., :1]), 42 / 255. * np.ones_like(x[..., :1]), 20 / 255. * np.ones_like(x[..., :1])), axis=2) color *= m[..., np.newaxis] x *= (1 - m[..., np.newaxis]) return np.clip(x + color, 0, 1) * 255
Example #11
Source File: make_imagenet_c_inception.py From robustness with Apache License 2.0 | 4 votes |
def spatter(x, severity=1): c = [(0.65,0.3,4,0.69,0.9,0), (0.65,0.3,3.5,0.68,0.9,0), (0.65,0.3,3,0.68,0.8,0), (0.65,0.3,1.2,0.65,1.8,1), (0.67,0.4,1.2,0.65,1.8,1)][severity - 1] x = np.array(x, dtype=np.float32) / 255. liquid_layer = np.random.normal(size=x.shape[:2], loc=c[0], scale=c[1]) liquid_layer = gaussian(liquid_layer, sigma=c[2]) liquid_layer[liquid_layer < c[3]] = 0 if c[5] == 0: liquid_layer = (liquid_layer * 255).astype(np.uint8) dist = 255 - cv2.Canny(liquid_layer, 50, 150) dist = cv2.distanceTransform(dist, cv2.DIST_L2, 5) _, dist = cv2.threshold(dist, 20, 20, cv2.THRESH_TRUNC) dist = cv2.blur(dist, (3, 3)).astype(np.uint8) dist = cv2.equalizeHist(dist) # ker = np.array([[-1,-2,-3],[-2,0,0],[-3,0,1]], dtype=np.float32) # ker -= np.mean(ker) ker = np.array([[-2, -1, 0], [-1, 1, 1], [0, 1, 2]]) dist = cv2.filter2D(dist, cv2.CV_8U, ker) dist = cv2.blur(dist, (3, 3)).astype(np.float32) m = cv2.cvtColor(liquid_layer * dist, cv2.COLOR_GRAY2BGRA) m /= np.max(m, axis=(0, 1)) m *= c[4] # water is pale turqouise color = np.concatenate((175 / 255. * np.ones_like(m[..., :1]), 238 / 255. * np.ones_like(m[..., :1]), 238 / 255. * np.ones_like(m[..., :1])), axis=2) color = cv2.cvtColor(color, cv2.COLOR_BGR2BGRA) x = cv2.cvtColor(x, cv2.COLOR_BGR2BGRA) return cv2.cvtColor(np.clip(x + m * color, 0, 1), cv2.COLOR_BGRA2BGR) * 255 else: m = np.where(liquid_layer > c[3], 1, 0) m = gaussian(m.astype(np.float32), sigma=c[4]) m[m < 0.8] = 0 # m = np.abs(m) ** (1/c[4]) # mud brown color = np.concatenate((63 / 255. * np.ones_like(x[..., :1]), 42 / 255. * np.ones_like(x[..., :1]), 20 / 255. * np.ones_like(x[..., :1])), axis=2) color *= m[..., np.newaxis] x *= (1 - m[..., np.newaxis]) return np.clip(x + color, 0, 1) * 255