def test_writeImage(self): img_dims = (25600,25600) img_1 = np.ones(img_dims,'uint8') * 123 img_2 = img_1.copy() le.writeImage(img_1, self.filename) read_img = np.zeros(img_dims,'uint8') le.getImage(read_img,self.filename) assert((read_img==img_2).all(), True )
def makePredictions(inputFile): X, image, blocklist = getPredictionData(inputFile) click.echo('Loading trained network data....') #Load stored data from network try: with open('net.pickle', 'rb') as f: net_pretrain = pickle.load(f) net_pretrain.max_epochs = 25 # Train the previous model over more epochs except IOError as e: print "No trained network is available. Use train command to train first. " click.echo('') click.echo('Making predictions....') #Make predictions y_pred = net_pretrain.predict(X) #Checking to see if predictions detect any sand dunes. Outputs the indice where a 1 is found. ones = 0 zeroes = 0 array_dunes = [] for i in range(y_pred.shape[0]): if y_pred[i] == 1: ones+=1 array_dunes.append(i) elif y_pred[i] == 0: zeroes += 1 for x, y in enumerate(y_pred): if y == 1: blocklist[x][:] = 255 click.echo('') click.echo('Dune blocks detected followed by negative blocks.') print ones, zeroes click.echo('') click.echo('Adding predictions to input image....') #Adding predictions to image data load_extension.writeImage(image, 'prediction.tif') click.echo('') click.echo('Writing image to directory....')
import Tkinter root = Tkinter.Tk() image_file = "PSP_009650_1755_RED" train_file = image_file+"_dunes.tif" image_file += ".tif" rows, cols = load_extension.getDims(image_file) ratio = max((cols)/root.winfo_screenwidth(),(rows)/root.winfo_screenheight()) size = (cols /ratio , rows / ratio) sub_rows = rows/8 sub_cols = cols/4 print sub_rows, sub_cols image = np.zeros((rows,cols),"uint8") load_extension.getImage(image,image_file) # im = Image.fromarray(image[:sub_rows, sub_cols:]) #im.thumbnail(size,Image.ANTIALIAS) #im.show() # ones = np.ones((sub_rows,sub_cols),'uint8') # image = np.multiply(ones, image[:sub_rows, :sub_cols]) load_extension.writeImage( image[:sub_rows][sub_cols:], "test.tif") load_extension.getImage(image,train_file) load_extension.writeImage(image[:sub_rows][sub_cols:], "train.tif")
import load_extension import numpy as np import matplotlib.pyplot as plt import Tkinter import datetime from PIL import Image root = Tkinter.Tk() start = datetime.datetime.now() #assumes you have Ryans images in the same folder as this script filename ="PSP_009650_1755_RED.tif" #filename = "example.tif" #filename = "training_image.tif" training_file = "PSP_009650_1755_RED_dunes.tif" rows,cols = load_extension.getDims(filename) train_image = np.zeros((rows,cols),'uint8') image = np.zeros((rows,cols),'uint8') load_extension.getImage(image,filename) newfile = filename.split(".")[0] +"_flipped."+filename.split(".")[1] start = datetime.datetime.now() image = image[::-1] ones = np.ones((rows,cols),'uint8') image = np.multiply(ones, image) load_extension.writeImage(image,newfile) print datetime.datetime.now() -start
import load_extension import numpy as np import matplotlib.pyplot as plt import Tkinter import datetime from PIL import Image root = Tkinter.Tk() start = datetime.datetime.now() #assumes you have Ryans images in the same folder as this script filename = "PSP_009650_1755_RED.tif" #filename = "example.tif" #filename = "training_image.tif" training_file = "PSP_009650_1755_RED_dunes.tif" rows, cols = load_extension.getDims(filename) train_image = np.zeros((rows, cols), 'uint8') image = np.zeros((rows, cols), 'uint8') load_extension.getImage(image, filename) newfile = filename.split(".")[0] + "_flipped." + filename.split(".")[1] start = datetime.datetime.now() image = image[::-1] ones = np.ones((rows, cols), 'uint8') image = np.multiply(ones, image) load_extension.writeImage(image, newfile) print datetime.datetime.now() - start
import numpy as np from PIL import Image import Tkinter root = Tkinter.Tk() image_file = "PSP_009650_1755_RED" train_file = image_file + "_dunes.tif" image_file += ".tif" rows, cols = load_extension.getDims(image_file) ratio = max((cols) / root.winfo_screenwidth(), (rows) / root.winfo_screenheight()) size = (cols / ratio, rows / ratio) sub_rows = rows / 8 sub_cols = cols / 4 print sub_rows, sub_cols image = np.zeros((rows, cols), "uint8") load_extension.getImage(image, image_file) # im = Image.fromarray(image[:sub_rows, sub_cols:]) #im.thumbnail(size,Image.ANTIALIAS) #im.show() # ones = np.ones((sub_rows,sub_cols),'uint8') # image = np.multiply(ones, image[:sub_rows, :sub_cols]) load_extension.writeImage(image[:sub_rows][sub_cols:], "test.tif") load_extension.getImage(image, train_file) load_extension.writeImage(image[:sub_rows][sub_cols:], "train.tif")