標籤:
# coding=utf-8import Imageimport osimport csvimport numpy as np# openimg_path = r"G:\kangyufeng\pics"def myimage(img_path): try: img_list = os.listdir(img_path) except: print ‘not a document‘ return Bigm = 0.01 for img in img_list: if "tif" in img: print img im = Image.open(img_path+‘\\‘+img) #im.save("%s%s"%(img.split(".")[-2],‘.jpeg‘)) w,l=im.size source = im.split() R,G,B = 0,1,2 S = 0 count = 1 mtr = np.array(source[G]) mtr.transpose() mtr = mtr[l/2-300:l/2+300] mtr = mtr.reshape(1,w*600) print len(mtr[0]) mmean = mtr.mean() print mmean for i in mtr[0]: if i > mmean/10: S += i count += 1 m = S/count if Bigm < m: Bigm = m print m,count with open("%s%s%s%s" % (img_path,‘\\‘,img_path.split(‘\\‘)[-1],‘_results.csv‘),‘ab‘) as f: #如果不使用‘ab‘方式只用’a‘會產生多餘空行 f = csv.writer(f,dialect=‘excel‘) f.writerow([img,str(m),str(float(m)/Bigm*float(img_path.split(‘_‘)[-1]))+‘Mmol/L‘]) else: if ‘csv‘ not in img: myimage(img_path+‘\\‘+img)myimage(img_path)
python 處理映像(綠色亮度)
python 處理映像(綠色亮度)