Upload files to "/"

This commit is contained in:
RomanNum3ral 2024-10-27 14:31:31 +00:00
commit 0c1329c5c0
3 changed files with 46 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
.venv/
out_dir/

6
README.md Normal file
View File

@ -0,0 +1,6 @@
# Leaf Image Converter
Converts leaf images into the format required for multi class semantic segmentation.
## Instructions
run `python main.py input_directory ouput_directory`

38
main.py Normal file
View File

@ -0,0 +1,38 @@
import argparse
import os
import numpy as np
import cv2
import glob
parser = argparse.ArgumentParser()
parser.add_argument('input', type=str, default='', help='path to input directory')
parser.add_argument('output', type=str, default='', help='path to output directory')
args = parser.parse_args()
target = args.input
out_dir = args.output
targets = glob.glob(os.path.join(target+'*.png'))
for target in targets:
img = cv2.imread(target)
r = img[:,:,2] == 255
g = img[:,:,1] == 255
b = img[:,:,1] == 255
mask1 = np.logical_and(r, g, b)
mask2 = np.logical_and(r, np.logical_not(g),np.logical_not(b))
out = np.zeros(np.shape(mask1))
out[mask1] = 1
out[mask2] = 2
cv2.imwrite(os.path.join(out_dir,os.path.basename(target)), out)
# for x in glob.glob(os.pathout_dir+'/*.png'):
# test = cv2.imread(x,0)
# print(test.shape)
# pylab.imshow(test)
# pylab.show()