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
这两种方法处理工作目录中的 .tif 图像。我需要将前缀 IMAGENAME 添加到数字结果中(如:firstimage、6786876876 或 secondimage___67876876)。如何实现这个想法?