Skip to content
This repository has been archived by the owner on Jul 2, 2020. It is now read-only.

Commit

Permalink
reformat makehistgram.py
Browse files Browse the repository at this point in the history
  • Loading branch information
DaisukeMiyamoto committed Feb 13, 2017
1 parent f117c55 commit 589e27d
Showing 1 changed file with 28 additions and 30 deletions.
58 changes: 28 additions & 30 deletions registration/MakeHistgram.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'] = []
Expand All @@ -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')




# samplepath = os.path.join('..', 'private', 'work3', 'CD00002-IS-BR-21.tif')
# makeHist(samplepath, 'result.png')

0 comments on commit 589e27d

Please sign in to comment.