Skip to content

Instantly share code, notes, and snippets.

@Gotoryoo
Created November 29, 2016 05:24
Show Gist options
  • Save Gotoryoo/fd3f8a3d35516a237adb91d0c77c1f0e to your computer and use it in GitHub Desktop.
Save Gotoryoo/fd3f8a3d35516a237adb91d0c77c1f0e to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
"""
Created on Tue Aug 04 15:24:55 2015
@author: ryousuke
"""
import numpy
import cv2
import glob
import matplotlib.pyplot as plt
import sys
argvs = sys.argv
argc = len(argvs)
if argc != 4:
print "****"
print ">usage:{0} c:\\img_path layer_num imgname.png".format(argvs[0])
print "****"
exit()
filepath = "{0}\\*.bmp".format(argvs[1])
files = glob.glob(filepath)
#files.sort(key=os.path.getctime)
layer = int(argvs[2])
graphprefix = argvs[3]
depth = []
imean = []
imini = []
imaxi = []
for file in files:
print file
img = cv2.imread(file,cv2.CV_LOAD_IMAGE_GRAYSCALE)
gau =cv2.GaussianBlur(img, (3,3), 0)
imean.append( gau.mean())
imini.append(numpy.amin(gau))
imaxi.append( numpy.amax(gau))
filenamespl=file.split('\\')
depth.append( int(filenamespl[-1][2:-4])*5 )
diff = imaxi[layer]*1.0 - imini[layer]*1.0#base柱における明暗の差 これが基準になる。
icont = []
for i in range(len(depth)):
icont.append(( imaxi[i]*1.0 - imini[i]*1.0 )/ diff )
################### graph for brightness
plt.plot(depth, imaxi,label = 'maximum')
plt.plot(depth, imean,label = 'mean')
plt.plot(depth, imini,label = 'minimum')
plt.legend(loc="lower left")
plt.title('Brightness & Depth of emulsion in Z-axis')
plt.xlabel('Depth along Z-axis (micron)')
plt.ylabel('Brightness')
axis = plt.gca()
axis.set_ylim(0,280)
plt.savefig("{0}_b.png".format(graphprefix))
#plt.show()
################### graph for relative contrast
plt.cla()
plt.plot(depth, icont, label = 'contrast')
plt.legend(loc="upper left")
axis = plt.gca()
axis.set_ylim(0,1.5)#1.5を調節する。 自動で伸縮する
plt.savefig("{0}_c.png".format(graphprefix))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment