Commit 6bc47025 authored by Nina Montana Brown's avatar Nina Montana Brown

Added function to change RGB/Multichannel images to grayscale

parent f5275c26
Pipeline #4681 failed with stages
in 36 seconds
......@@ -3,6 +3,9 @@
""" Function to rename images in directories """
import os
import cv2
import numpy as np
from PIL import Image
def rename_image(input_dir, folder, name):
......@@ -78,3 +81,22 @@ def remove_string(input_dir, folder):
dest = item + folder + '_'.join(new[-3:])
source = item + folder + filename
os.rename(source, dest)
def rgb_to_gray(folder):
Function to convert all files in folder from multichannel images to
gray images
assert os.path.exists(folder), "Folder param not path"
files = os.listdir(folder)
for item in files:
# Open item
path_file = os.path.join(folder, item)
image = cv2.imread(path_file) # 0 flag reads as grayscale
grey = cv2.cvtColor(image, cv2.COLOR_BGRA2GRAY)
cv2.imwrite(path_file, grey)
if __name__ == "__main__":
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment