Coders Packet

Remove particular color from an image in Python

By Lakshay Sharma

A package that can be used to remove any particular color from an image in Python. A Basic GUI for openCV is also provided in python.

Remove particular color from an image in Python

A package that can be used to remove particular color from an image in Python.

 

Setup


Installing the base package

/Note:/ Better to use GUI as it uses openCV which is majorly supported. 

 

RAW CODE ONLY : (ColorRemoval.py)

     python -m pip install --upgrade Pillow

GUI ONLY : (GUI.py)

     pip install opencv-python
     pip install PySimpleGUI

 

 

How to use


ColorRemoval.py

    import ColorRemoval

    input_image_path = 'input_image.jpg'    # Replace with the path to your input image
    output_image_path = 'output_image.png'  # Replace with the desired output path
    target_color = (255, 0, 0)              # Replace with the RGB color you want to remove

    ColorRemoval.remove_color_from_image(input_image_path, output_image_path, target_color)

input_image.jpg
OriginalImage

>> When target_color == "RED" or (255,0,0)
removedRED

>> When target_color == "GREEN" or (0,255,0)
removedGREEN

>> When target_color == "BLUE" or (0,0,255)
removedBLUE

GUI.py

> GUI window

gui

 

Original image:

original

 

GreyScaled: 

Greyscaled

 

 

 

 

 

 

 

 

 

 

 

 

Add > (200,0,0) "RED"

red

 

Sub > (200,0,0) "RED"

subred

 

Filter > 

    lower_bound = (0,0,0) "black"

    upper_bound = (0,255,255) "not red" or "all except red color i.e. blue and green"

filterred

 

Convolutions > Blur

blur

 

Convolutions > Sharpen

sharpen

Download Complete Code

Comments

No comments yet

Download Packet

Reviews Report

Submitted by Lakshay Sharma (LakshaySharma)

Download packets of source code on Coders Packet