GLES remove logo from texture with a black and white mask - opengl-es

I would like to delete a portion of a texture defined by a black and white mask and replace it with the color of the adjacent pixels
this is an example to make you understand better
this is my try
first I draw the mask with the white area with the part of the image to be preserved and black with the portion to be obscured with
glDisable (GL_BLEND);
then I draw over the image with
glEnable (GL_BLEND);
glBlendFunc (GL_DST_COLOR, GL_ZERO);
in this way I can delete the part defined by the mask but I don't know how to fill it inside with the colors of the adjacent pixels
thx!
EDIT
I found this shadertoy that does exactly what i'm looking for
https://www.shadertoy.com/view/4ty3Dy
but I have to apply this to a video, and this shader seems to modify a static image multiple times by calling itself while the frames are running
I should have the effect generated for each frame in the simplest and lighter manner to run the shader on a rpi4

Related

HTML5 canvas - make a mono mask efficiently without antialiasing

I am using pixel colour inspection to detect collisions. I know there are other ways to achieve this but this is my use case.
I draw a shape cloned from the main canvas on to a second canvas switching the fill and stroke colours to pur black. I then use getImageData() to get an array of pixel colours and inspect them - if I see black I have a collision with something.
However, some pixels are shades of grey because the second canvas is applying antialiasing to the shape. I want only black or transparent pixels.
How can I get the second canvas to be composed of either transparent or black only?
I have achieved this long in the past with Windows GDI via compositing/xor combinations etc. However, GDI did not always apply antialiasing. I guess the answer lies in globalCompositeOperation or filter but I cannot see what settings/filters or sequence to apply.
I appreciate I have not provided sample code but I am hoping that someone can throw me a bone and I'll work up a snippet here which might become a standard cut & paste for posterity from that.

Draw texture to FrameBufferObject using specific color

I have a texture and I want to draw it to a FrameBufferObject. The texture has transparent areas. I would like the following:
For all transparent pixels, let them be drawn transparent in the FrameBufferObject.
For all non-transparent pixels, let them be drawn using a color of my choosing, ie pure red (ignore their actual rgb value)
I've tried Batch.setColor(red) before drawing the texture, but that just tints it - I want all non-transparent pixels to be drawn pure red.
I am also trying to figure out how to achieve this in just opengl directly, looks like there may be a way to do this with blending, which can then be related back to gdx.
Thanks
You need to write a shader and the shader is the OpenGL program that renders the texture. So your shader would render transparency without change and all else would the color of your own choosing.
The following link has libgdx shaders for palette swapping i.e. direct reassignment of color at render, which you can easily adapt for single color and transparency.
https://www.javaer101.com/en/article/12241616.html

How to change white background to transparent in golang?

How to change a Golang image.Image's white background to transparent?
I want to put the white background into a translucent color, do you have any suggestions?
This is not possible in general but there are heuristic approaches to attempt this.
Why is it not possible?
If the original image had some transparent pixels and was rendered on a plain white background (or any known background) then in the resulting image there is lost information. For example, is a pink pixel created from a red pixel with some transparency or a truly pink pixel without transparency?
Even a pure white pixel may have been fully white originally, or fully transparent, or somewhere in between.
Heuristic approaches
If you know something about the original image or can infer something by looking at it you may be able to deduce what colour and transparency of the original pixels was. A simple first step is that if the outside pixels are white then you might want to flood fill this area with fully transparent pixels. Also white areas inside coloured areas may be holes that can also be transparent.
Next you can infer the colours of border pixels around objects of a single colour (assuming transparency was used for anti-aliasing). For example for a red circle with pink pixels on the circumference it's likely they were originally red with some transparency leading them to be rendered in different shades of pink. For more complex, multi-coloured shapes you can get a reasonable result by manually editing the image using judgement, knowledge/guesswork of the original image and knowledge of how anti-aliasing was performed.
I wrote a Paint.Net plugin (C#) to automate this sort of thing many years ago and sometimes it gave reasonable results, but often you need to do it by hand.
package "image" has Decode function
func Decode(r io.Reader) (Image, string, error)
image.Image is interface
type Image interface {
// ColorModel returns the Image's color model.
ColorModel() color.Model
// Bounds returns the domain for which At can return non-zero color.
// The bounds do not necessarily contain the point (0, 0).
Bounds() Rectangle
// At returns the color of the pixel at (x, y).
// At(Bounds().Min.X, Bounds().Min.Y) returns the upper-left pixel of the grid.
// At(Bounds().Max.X-1, Bounds().Max.Y-1) returns the lower-right one.
At(x, y int) color.Color
}
after you decode you file into image.Image, you can get Height and Width from Bounds(),and color from At(x,y).
So, here is what to do next:
make another image with alpha channel,
Iterate throw whole image one pix by another,
check color, copy color to new image after you do whatever you want.

Removing semi-transparent overlay on flattened image

A solution to this problem seems to not exist but I find it hard to believe it is not possible.
Imagine you have an image with a semi-transparent overlay (color=black, transparency=50%), whether over the whole image or just a portion, doesn't matter. How could one convert the pixels underneath to their original color, in essence removing the black overlay.
Just like a simple algebra equation we should be able to rearrange the variables to solve for the "original pixels" under the overlay. Something along the lines of -
original pixels * semi-transparent overlay = new pixelsoriginal pixels = semi-transparent overlay / new pixels
Obviously such an equation over simplifies the problem but I think that gets my point across. Since we know the color and percent transparency, why couldn't we "retrieve" the colors of the underlying pixels?
EDIT: Mark Ransom in the comments is correct, if you know the transparency is 50% then simply multiplying by 2 gets you to the original color. Any recommendations on how to apply this to a whole region in Photoshop or GIMP? Certainly doing it pixel by pixel is out of the question.
Thank you!
The "divide" layer mode will do what you want. In the case of semi-transparent black, use a gray with the value equal to the opacity value of the overlayed layer.

How can I have a png image with transparency, visible only from *front*?

I'm using a prefab for a box shape, which has a front and back plane.
My images are PNG and have transparent areas around the edge. I dragged the image onto my front plane, which now has a drop-down box for "Shader".
First I chose Shader: "Standard" but the transparent areas of my PNG image weren't transparent, so in order to fix that I changed it to "Sprites / Diffuse"... now the image looks fine (from the front).
However, when I rotate the shape, the image is also visible from the back. I want a way to not see the image / texture from the back.
How can I make the images only visible from the front side of a plane, whilst also preserving the transparency areas of the image / texture?
If you are using the standard built-in shader, you need to set the rendering mode to transparent in order for the texture's alpha channel to be transparent. The sprite shader, by default, forces the rendering of otherwise invisible back-faces, whereas the standard shader does not.

Resources