Created
February 17, 2019 07:31
-
-
Save suyashdamle/403a66eb8be4986830fa5fd206fe9700 to your computer and use it in GitHub Desktop.
Trim images in bulk using opencv to pre-defined dimensions (implemented for grayscale images)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import numpy as np | |
import cv2 | |
from scipy.misc import imsave | |
DIR = './' | |
LEFT=190 | |
RIGHT=1246 | |
TOP=0 | |
BOTTOM=590 | |
for file_name in os.listdir(DIR): | |
if '.png' not in file_name: | |
continue | |
img=cv2.imread(DIR+file_name,cv2.IMREAD_GRAYSCALE) | |
img=img[TOP:BOTTOM,LEFT:RIGHT] | |
imsave('new_'+file_name,img) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment