Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions image_colour_to_bw/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Script to convert coloured images to black and white
## How to use:
1. Make the directory structure as shown below:
<br>.
<br>├── colour_to_bw.py
<br>└── image.png

2. Call the function giving two arguments, the path to the original image and the path for your output image
<br> example :-
<br>```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.
<br>.
<br>├── colour_to_bw.py
<br>├── final_image.png
<br>└── ptr_mail.apng
12 changes: 12 additions & 0 deletions image_colour_to_bw/colour_to_bw.py
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions image_colour_to_bw/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
opencv-python