Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
   def generalarea(self):
  for filename in glob.iglob ('*.tif'):
    img = np.asarray(Image.open(filename).convert('L'))                            
    img = 1 * (img < 127)
    garea = (img == 0).sum()
    print garea

def areasplit(self):
  for filename in glob.iglob ('*.tif'):    
    img = np.asarray(Image.open(filename).convert('L'))                            
    img = 1 * (img < 127)
    areasplit = np.split(img.ravel(), 24) # here we are splitting converted to 1D array
  for i in areasplit:
   sarea = (i == 0).sum()
   print sarea

These two methods process .tif images in the working directory. I need to add the prefix IMAGENAME to the number result (to get like: firstimage, 6786876876 or secondimage___67876876). How to implement that idea?

share|improve this question

1 Answer

For example, for the first function, instead of print garea, you could have:

print "%s___%d" % (filename, garea)

or "%s, %d" if you want a comma. See Python's doc on string formatting operations.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.