码迷,mamicode.com
首页 > 编程语言 > 详细

python 处理图像(绿色亮度)

时间:2015-03-21 18:31:16      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:

# coding=utf-8
import Image
import os
import csv
import numpy as np
# open
img_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 处理图像(绿色亮度)

标签:

原文地址:http://www.cnblogs.com/shyustc/p/4355899.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!