I have issue where I have transparent part of image, but I am not sure if it really is transparent because I can not see what is behind transparent part and it is look like there is nothing but under it should be another image, problem looks like this or like this. If I do not use masks for deleting black edges it looks like this
I want to make edges completely transparent or entirely delete them.
Thank you for your help. Have a nice day
this is how I load image
trainImg = cv2.imread(fnames[x], cv2.IMREAD_UNCHANGED)
trainImg_gray = cv2.cvtColor(trainImg, cv2.COLOR_RGB2GRAY)
queryImg = cv2.imread(fnames[y], cv2.IMREAD_UNCHANGED)
queryImg_gray = cv2.cvtColor(queryImg, cv2.COLOR_RGB2GRAY)
this is how I work with pictures
height = trainImg.shape[0] + queryImg.shape[0]
width = trainImg.shape[1] + queryImg.shape[1]
dim = (trainImg.shape[1], trainImg.shape[0])
print(fnames_cropped[x])
trainImg = cv2.imread(fnames_cropped[x])
(b, g, r) = cv2.split(trainImg)
trainImg = cv2.merge([r, g, b])
trainImg = cv2.resize(trainImg, dim)
trainImg = trim(trainImg)
dim = (queryImg.shape[1], queryImg.shape[0])
print(fnames_cropped[y])
queryImg = cv2.imread(fnames_cropped[y])
(b, g, r) = cv2.split(queryImg)
queryImg = cv2.merge([r, g, b])
queryImg = cv2.resize(queryImg, dim)
queryImg = trim(queryImg)
# Make mask of black pixels - mask is True where image is black
RGB = np.array(trainImg)
h, w = RGB.shape[:2]
# Add an alpha channel, fully opaque (255)
RGBA = np.dstack((RGB, np.zeros((h, w), dtype=np.uint8) + 255))
# Make mask of black pixels - mask is True where image is black
mBlack = (RGBA[:, :, 0:3] == [0, 0, 0]).all(2)
# Make all pixels matched by mask into transparent ones
RGBA[mBlack] = (0, 0, 0, 0)
trainImg = RGBA
# Make mask of black pixels - mask is True where image is black
RGB = np.array(queryImg)
h, w = RGB.shape[:2]
# Add an alpha channel, fully opaque (255)
RGBA = np.dstack((RGB, np.zeros((h, w), dtype=np.uint8) + 255))
# Make mask of black pixels - mask is True where image is black
mBlack = (RGBA[:, :, 0:3] == [0, 0, 0]).all(2)
# Make all pixels matched by mask into transparent ones
RGBA[mBlack] = (0, 0, 0, 0)
queryImg = RGBA
result = cv2.warpPerspective(trainImg, H, (width, height), flags=cv2.INTER_NEAREST, borderMode=cv2.BORDER_CONSTANT)
im = Image.fromarray(trim(result))
result[0:queryImg.shape[0], 0:queryImg.shape[1]] = queryImg
im = Image.fromarray(trim(result))
im.save(feature_extractor+feature_matching+fnames_cropped[x]+fnames_cropped[y])