# Add to list fileList.extend(tempFile.readlines()) tempFile.close() # Remove newlines fileList = [file[: len(file) - 1] for file in fileList] # Grab image size image = pl.imread(fileList[0]) (Y, X) = np.shape(image) # Grab total number of frames numFrames = len(fileList) # Set output filename outputFileName = outputFileDir + "depth_0" + str(eyeVal) + ".pvp" # Open output file outMatFile = open(outputFileName, "wb") # Write out header writeHeaderFile(outMatFile, (Y, X, numBins), numFrames) # Calculate stepSize based on number of bins stepSize = float(1) / numBins normVal = 1 / (stepSize * sqrt(2 * pi)) for frameIdx, depthFile in enumerate(fileList): print "Creating file", depthFile image = pl.imread(depthFile) # Make sure the size is the same (Ytest, Xtest) = np.shape(image) assert Y == Ytest and X == Xtest depthMat = np.zeros((Y, X, numBins)) binImage = np.zeros((Y, X, numBins)) for bin in range(numBins): binupthresh = stepSize * (bin + 1) binlowthresh = stepSize * (bin) mat1 = image < binupthresh
for binRange in range(-numSigma, numSigma+1): curBin = bin + binRange if curBin < 0 or curBin >= numBins: continue upthresh = stepSize * (curBin + 1) lowthresh = stepSize * (curBin) #Calculate cumulative distribution #Using center of stepsize xVal = lowthresh + (float(upthresh - lowthresh)/2) outmat = (normpdf(xVal, idxMat, stepSize)) * binMat[:,:,bin] posMat[:, :, curBin] += outmat[:,:] #Normalize with mean/std matMean = np.mean(posMat) matStd = np.std(posMat) posMat = (posMat - matMean) * (targetStd/matStd) + targetMean writeHeaderFile(outMatFile, (Y, X, numBins), 1) writeData(outMatFile, posMat, 1) outMatFile.close() #y, x, z = posMat.nonzero() # #fig = plt.figure() #ax = Axes3D(fig) #ax.scatter(x, z, -y, zdir = 'z', color = 'r') #plt.show()
for binRange in range(-numSigma, numSigma + 1): curBin = bin + binRange if curBin < 0 or curBin >= numBins: continue upthresh = stepSize * (curBin + 1) lowthresh = stepSize * (curBin) #Calculate cumulative distribution #Using center of stepsize xVal = lowthresh + (float(upthresh - lowthresh) / 2) outmat = (normpdf(xVal, idxMat, stepSize)) * binMat[:, :, bin] posMat[:, :, curBin] += outmat[:, :] #Normalize with mean/std matMean = np.mean(posMat) matStd = np.std(posMat) posMat = (posMat - matMean) * (targetStd / matStd) + targetMean writeHeaderFile(outMatFile, (Y, X, numBins), 1) writeData(outMatFile, posMat, 1) outMatFile.close() #y, x, z = posMat.nonzero() # #fig = plt.figure() #ax = Axes3D(fig) #ax.scatter(x, z, -y, zdir = 'z', color = 'r') #plt.show() #Write out header #only 1 frame # writeHeaderFile(outMatFile, (Y, X, numBins), 1) #for bin in range(numBins):
#Add to list fileList.extend(tempFile.readlines()) tempFile.close() #Remove newlines fileList = [file[:len(file) - 1] for file in fileList] #Grab image size image = pl.imread(fileList[0]) (Y, X) = np.shape(image) #Grab total number of frames numFrames = len(fileList) #Set output filename outputFileName = outputFileDir + "depth_0" + str(eyeVal) + ".pvp" #Open output file outMatFile = open(outputFileName, 'wb') #Write out header writeHeaderFile(outMatFile, (Y, X, numBins), numFrames) #Calculate stepSize based on number of bins stepSize = float(1) / numBins normVal = 1 / (stepSize * sqrt(2 * pi)) for frameIdx, depthFile in enumerate(fileList): print "Creating file", depthFile image = pl.imread(depthFile) #Make sure the size is the same (Ytest, Xtest) = np.shape(image) assert (Y == Ytest and X == Xtest) depthMat = np.zeros((Y, X, numBins)) binImage = np.zeros((Y, X, numBins)) for bin in range(numBins): binupthresh = stepSize * (bin + 1) binlowthresh = stepSize * (bin) mat1 = image < binupthresh