import cv2 import numpy as np import mwTools # Define the fields to process fields = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] for field in fields: print('Processing field ' + str(field)) # Load the bgr files print('Loading field ' + str(field)) with np.load('fied'+str(field)+'-clean.npz') as data: redData = data['redData'] blueData = data['blueData'] # Remove the negative values redData[redData < 0] = 0 blueData[blueData < 0] = 0 # Create the green dataset print('Creating green dataset...') greenData = (redData + blueData)/2.0 # Calculate the maximum signal values print('Calculating maximum and minimum signal values...') def maxValFunction(x): return 1.1 + 1.7*(np.sin(np.pi*(x + field*redData.shape[1])/(15*redData.shape[1]))**3) def minValFunction(x): return 0.1*(np.sin(np.pi*(x + field*redData.shape[1])/(15*redData.shape[1]))**3) maxValue = np.fromfunction(maxValFunction, (redData.shape[1],)) minValue = np.fromfunction(minValFunction, (redData.shape[1],)) print('Maximum value range: (' + str(round(maxValue[0],1)) + ', ' + str(round(maxValue[-1],1)) + ')') # Calculate the bgr colors print('Calculating bgr colors...') exponent = 0.5 redData = mwTools.getColorIntensity(redData, minValue, maxValue, exponent) blueData = mwTools.getColorIntensity(blueData, minValue, maxValue, exponent) greenData = mwTools.getColorIntensity(greenData, minValue, maxValue, exponent) # Save the results print('Saving bgr file...') np.savez('fied'+str(field)+'.npz', bgrData=cv2.merge([blueData, greenData, redData]))