Spaces:
Sleeping
Sleeping
Create app.py
Browse files123456789101112131415161718192021222324252627282930313233343536import gradio as grfrom PIL import Image
def dark_pixels_only(input_image): """ Takes an image, converts to RGBA, and makes any pixel with ANY component above 15 fully transparent. """ # Convert image to RGBA img = input_image.convert("RGBA") pixels = img.getdata()
new_pixels = [] for (r, g, b, a) in pixels: # Keep pixel's original alpha if all components are <= 15, # otherwise make fully transparent. if r <= 15 and g <= 15 and b <= 15: new_pixels.append((r, g, b, a)) else: new_pixels.append((r, g, b, 0))
img.putdata(new_pixels) return img
demo = gr.Interface( fn=dark_pixels_only, inputs=gr.Image(type="pil"), outputs=gr.Image(type="pil"), title="Make Non-Dark Pixels Transparent", description="Upload an image. Any pixel with an R, G, or B value above 15 " "will be made fully transparent. Pixels with R, G, B all ≤ 15 " "retain their original alpha.")
if __name__ == "__main__": demo.launch()app.pyAdded+36