diff --git a/image_colour_to_bw/README.md b/image_colour_to_bw/README.md new file mode 100644 index 000000000..d58e52b2f --- /dev/null +++ b/image_colour_to_bw/README.md @@ -0,0 +1,16 @@ +# Script to convert coloured images to black and white +## How to use: +1. Make the directory structure as shown below: +
. +
├── colour_to_bw.py +
└── image.png + +2. Call the function giving two arguments, the path to the original image and the path for your output image +
example :- +
```colour_to_bw("./image.png","./")``` + +3. The output of the script will be stored as "final_image.png". The directory structure would look similar to this if you execute the code in step 2. +
. +
├── colour_to_bw.py +
├── final_image.png +
└── ptr_mail.apng diff --git a/image_colour_to_bw/colour_to_bw.py b/image_colour_to_bw/colour_to_bw.py new file mode 100644 index 000000000..fd744d262 --- /dev/null +++ b/image_colour_to_bw/colour_to_bw.py @@ -0,0 +1,12 @@ +import cv2 + + +def colour_to_bw(original_image_path, output_path): + ''' + Function to convert colour image to black and white + ''' + original_image = cv2.imread(original_image_path) + gray_img = cv2.cvtColor(original_image, cv2.COLOR_BGR2GRAY) + thresh = 128 + img_bw = cv2.threshold(gray_img, thresh, 255, cv2.THRESH_BINARY)[1] + cv2.imwrite(output_path + 'final_image.png', img_bw) diff --git a/image_colour_to_bw/requirements.txt b/image_colour_to_bw/requirements.txt new file mode 100644 index 000000000..1db7aea11 --- /dev/null +++ b/image_colour_to_bw/requirements.txt @@ -0,0 +1 @@ +opencv-python \ No newline at end of file