In [ ]:
# analyze the Bright and Dark images
import cv2
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import matplotlib.colors as mc
def display_surface(img):
size = 1024 #1920
w,h = img.shape
w2 = w / 2
h2 = h / 2
img = img[h2 : h2 + size, h2 : h2 + size]
imin = np.min(img)
imax = np.max(img)
cmap = plt.cm.jet
print imax, imin, cmap.N
#norm = mc.BoundaryNorm(imax-imin, cmap.N)
fig=plt.figure()
ax = Axes3D(fig)
w,h = img.shape
xx, yy = np.mgrid[0:w, 0:h]
# plot3D requires a 1D array for x, y, and z
# ravel() converts the 100x100 array into a 1x10000 array
#ax.plot_surface(xx,yy,img, cmap=plt.cm.jet)
ax.plot_surface(xx,yy,img, linewidth=0, cmap=cmap, antialiased=False, shade=False, )
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
fig.add_axes(ax)
plt.show()
def display_image(img):
clicked = False
def onMouse( event, x, y, flags, param):
global clicked
if event == cv2.EVENT_LBUTTONUP:
clicked = True
cv2.namedWindow('MyWindow')
cv2.setMouseCallback('MyWindow', onMouse)
print 'Press any key to stop.'
while cv2. waitKey( 1) == -1 and not clicked:
cv2. imshow('MyWindow', img)
cv2. destroyWindow('MyWindow')
temca1BDark = r"C:\temca\temca1\config\DarkField_48500328.tif"
temca1Bright = r"C:\temca\temca1\config\BrightField_48500328.tif"
temca2Dark = r"C:\temca\temca2\config\DarkField_44500428.tif"
temca2Bright = r"C:\temca\temca2\config\BrightField_44500428.tif"
bright_file = temca2Bright
dark_file = temca2Dark
iDark = cv2.imread(dark_file, cv2.IMREAD_UNCHANGED)
iBright = cv2.imread(bright_file, cv2.IMREAD_UNCHANGED)
iBrightMinusDark = iBright - iDark
iBrightMinusDarkU8 = np.array(iBrightMinusDark / 256, np.uint8)
iBrightMinusDarkF32 = np.array(iBrightMinusDark, np.float32)
iCorrected = np.array(iBrightMinusDarkF32, np.uint16)
img = iBrightMinusDarkU8
#img = iBright / 256
display_surface(img)
# display_image(img)
In [ ]: