python - Brand new to scipy/numpy and attempting some batch manipulation -



python - Brand new to scipy/numpy and attempting some batch manipulation -

so, have bunch of scanned images annoying white around them want remove. i'm prepping algorithm using numpy arrays find closest pixel row , columns of finish white, cropping them positions. code:

from scipy import misc import os import datetime a0 = datetime.datetime.now() print("imported @ " + str(a0)) def run(): inputdir = '/users/nicholasezyk/documents/funeralhomescans' os.chdir(inputdir) #batch image renaming counter = 1 file in os.listdir(inputdir): if file.endswith('.jpg'): img = misc.imread(file) print(file + ' beingness analyzed.') cropx = -1 cropy = -1 lx = img.shape[0] ly = img.shape[1] countx = 0 county = 0 while countx < lx: pix = img[countx, 0] if pix == (255, 255, 255): tempcountx = 1 scorex = 1 while tempcountx < ly: if img[countx, tempcountx] == (255, 255, 255): scorex = scorex + 1 tempcountx = tempcountx + 1 if 1000 * (scorex / ly) > 1000: cropx = tempcountx break while county < ly: pix = img[0, county] if pix == (255, 255, 255): tempcounty = 1 scorey = 1 while tempcounty < lx: if img[tempcounty, county] == 255: scorey = scorey + 1 tempcounty = tempcounty + 1 if 1000 * (scorey / lx) == 1000: cropy = tempcounty break send = img[0:cropx, 0:cropy] misc.imsave('crop' + str(counter) + '.png', send) print(file + ' cropped , exported ' + 'crop' + str(counter) + '.png') run()

right now, console statement:

imported @ 2014-10-04 15:12:32.237369 test.jpg beingness analyzed. traceback (most recent phone call last): file "/users/nicholasezyk/documents/whiteout.py", line 52, in <module> run() file "/users/nicholasezyk/documents/whiteout.py", line 26, in run if pix == (255, 255, 255): valueerror: truth value of array more 1 element ambiguous. utilize a.any() or a.all()

since i'm unfamiliar syntax, if help me figure out how work numpy arrays, that'd fantastic.

python arrays numpy scipy batch-processing

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -