Hello everyone,
currently I am working with grey-scale images, and I thought it would be a nice idea to have an opportunity to convert Grayscale images into Grayscale+Alpha images.
I had a look here: OpenCV: Color Space Conversions
but I could only find GRAY2RGB
, GRAY2BGRA
and RGB2RGBA
. So I think a conversion GRAY2GRAYA
is missing in this place. To show that this is something useful: The png format has support for these Grayscale+Alpha images: PNG Basics (PNG: The Definitive Guide)
And here is an example python script, where reducing these 4 channels to only 2 channels would make a benefit:
from matplotlib import pyplot as plt
import numpy as np
from skimage import data
import cv2
camera = data.camera()
print(camera.shape)
camera = cv2.cvtColor(camera, cv2.COLOR_RGB2RGBA)
plt.imshow(camera, interpolation='nearest', cmap='gray');
(512, 512)
camera.shape
(512, 512, 4)
pad= np.full((int(camera.shape[0]/4), camera.shape[1]) ,0)
new_pad = cv2.cvtColor(np.uint8(pad), cv2.COLOR_GRAY2BGRA)
new_pad[:,:,3]=0 # setting alpha channle to zero
camera_new=np.concatenate((new_pad, camera ,new_pad) ,axis=0)
plt.imshow(camera_new, interpolation='nearest', cmap='gray');