Changing colour of a surface without overwriting transparency

You can achieve this by 2 steps. self.original_image contains the filled rectangle with the desired color: self.original_image.fill(self.colour) Generate a completely white rectangle and transparent areas. Blend the rectangle with (self.image) and the blend mode BLEND_MAX (see pygame.Surface.blit): whiteTransparent = pg.Surface(self.image.get_size(), pg.SRCALPHA) whiteTransparent.fill((255, 255, 255, 0)) self.image.blit(whiteTransparent, (0, 0), special_flags=pg.BLEND_MAX) Now the rectangle is completely white, … Read more

Is it possible to do additive blending with matplotlib?

If you only need an image as the result, you can get the canvas buffer as a numpy array, and then do the blending, here is an example: from matplotlib import pyplot as plt import numpy as np fig, ax = plt.subplots() ax.scatter(x1,y1,c=”b”,edgecolors=”none”) ax.set_xlim(-4, 4) ax.set_ylim(-4, 4) ax.patch.set_facecolor(“none”) ax.patch.set_edgecolor(“none”) fig.canvas.draw() w, h = fig.canvas.get_width_height() img … Read more

Blending does not remove seams in OpenCV

I choose to define the alpha value depending on the distance to the “object center”, the further the distance from the object center, the smaller the alpha value. The “object” is defined by a mask. I’ve aligned the images with GIMP (similar to your warpPerspective). They need to be in same coordinate system and both … Read more

OpenGL – mask with multiple textures

This should work: glEnable(GL_BLEND); // Use a simple blendfunc for drawing the background glBlendFunc(GL_ONE, GL_ZERO); // Draw entire background without masking drawQuad(backgroundTexture); // Next, we want a blendfunc that doesn’t change the color of any pixels, // but rather replaces the framebuffer alpha values with values based // on the whiteness of the mask. In … Read more