From 589e27da92f818c34d2396fc824ac1f40e6ff9ea Mon Sep 17 00:00:00 2001 From: nebula Date: Mon, 13 Feb 2017 19:13:59 +0900 Subject: [PATCH] reformat makehistgram.py --- registration/MakeHistgram.py | 58 +++++++++++++++++------------------- 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/registration/MakeHistgram.py b/registration/MakeHistgram.py index 7fdfa75..524063c 100755 --- a/registration/MakeHistgram.py +++ b/registration/MakeHistgram.py @@ -6,16 +6,17 @@ """ import sys import os -#import Image, ImageDraw +# import Image, ImageDraw from PIL import Image, ImageDraw import numpy as np import matplotlib.pyplot as plt + def makeHist(inpath, outfile): img = Image.open(inpath) print img.size rawimage = img.getdata() - + hist = {} hist['red'] = [] hist['green'] = [] @@ -26,46 +27,43 @@ def makeHist(inpath, outfile): hist['red'].append(pix[0]) hist['green'].append(pix[1]) hist['blue'].append(pix[2]) - hist['sum'].append((pix[0]+pix[1]+pix[2])/3) - - processed_pix = (pix[2]*2 - (pix[0] + pix[1]))*2 - #if processed_pix < 0: + hist['sum'].append((pix[0] + pix[1] + pix[2]) / 3) + + processed_pix = (pix[2] * 2 - (pix[0] + pix[1])) * 2 + # if processed_pix < 0: # processed_pix = 0 hist['processed'].append(processed_pix) - #hist = img.histogram() - #print hist - - plt.hist(hist['red'], histtype='step', bins=128, alpha=0.5, color='red', range=(1,255)) - plt.hist(hist['green'], histtype='step', bins=128, alpha=0.5, color='green', range=(1,255)) - plt.hist(hist['blue'], histtype='step', bins=128, alpha=0.5, color='blue', range=(1,255)) - plt.hist(hist['sum'], histtype='step', bins=128, alpha=0.5, color='gray', range=(1,255)) + # hist = img.histogram() + # print hist + + plt.hist(hist['red'], histtype='step', bins=128, alpha=0.5, color='red', range=(1, 255)) + plt.hist(hist['green'], histtype='step', bins=128, alpha=0.5, color='green', range=(1, 255)) + plt.hist(hist['blue'], histtype='step', bins=128, alpha=0.5, color='blue', range=(1, 255)) + plt.hist(hist['sum'], histtype='step', bins=128, alpha=0.5, color='gray', range=(1, 255)) plt.savefig(outfile) plt.show() - + out_img = Image.new('L', img.size) out_img.putdata(hist['processed']) - #out_img.save(outfile) - - #plt.hist(hist['processed'], histtype='step', bins=128, alpha=0.5, color='gray', range=(1,255)) - #plt.show() - - + # out_img.save(outfile) + + # plt.hist(hist['processed'], histtype='step', bins=128, alpha=0.5, color='gray', range=(1,255)) + # plt.show() + if __name__ == '__main__': workdir = os.path.join('..', 'private', 'work3') - outdir = os.path.join('..', 'private', 'processed') - + outdir = os.path.join('..', 'private', 'processed') + files = os.listdir(workdir) for filename in files: infile = os.path.join(workdir, filename) root, ext = os.path.splitext(filename) - outfile = os.path.join(outdir, root+'.png') - + outfile = os.path.join(outdir, root + '.png') + print infile, outfile makeHist(infile, outfile) - - - #samplepath = os.path.join('..', 'private', 'work3', 'CD00002-IS-BR-21.tif') - #makeHist(samplepath, 'result.png') - - \ No newline at end of file + + + # samplepath = os.path.join('..', 'private', 'work3', 'CD00002-IS-BR-21.tif') + # makeHist(samplepath, 'result.png')