def test_makePredictions(self): cn.trainNetwork(5, self.testfile, self.trainfile) cn.makePredictions(self.testfile) rows, cols = load_extension.getDims(self.testfile) predimage = 'prediction.tif' testrows, testcols = load_extension.getDims(predimage) self.assertEqual((rows, cols), (testrows, testcols)) self.assertIs(type(testrows), int) self.assertIs(type(testcols), int)
def get_labeled_data(filename, training_file, block_size=32): """Read input-array (image) and label-images and return it as list of tuples. """ rows,cols = load_extension.getDims(filename) print rows,cols image = np.ones((rows, cols), 'uint8') label_image = np.ones((rows, cols), 'uint8') # x is a dummy to use as a form of error checking will return false on error x = load_extension.getImage(image, filename) x = load_extension.getTraining(label_image, filename, training_file) X = [] y = [] for i in xrange(0,rows,block_size): for j in xrange(0,cols,block_size): try: X.append(image[i:i + block_size, j:j + block_size].reshape(1, block_size * block_size)) y.append(int(load_extension.getLabel(label_image[i:i + block_size, j:j + block_size], "1", "0", 0.75))) except ValueError: continue X = np.array(X).astype(np.float32) label_blocks = np.array(y).astype(np.int32) test_blocks = X.reshape(-1, 1, block_size, block_size) return test_blocks, label_blocks
def setUpClass(self): # pass mt.make() self.testfile = 'test.tif' self.trainfile = 'train.tif' self.downloadfile = 'TRA_000823_1720_COLOR.JP2' temp = np.ones((256, 256), 'uint8') * 125 self.rows, self.cols = load_extension.getDims(self.testfile) test_image = Image.fromarray(temp) test_image.save(self.testfile) self.image_8bit = np.array(Image.open(self.testfile)) train_image = Image.fromarray(temp) train_image.save(self.trainfile) self.image_8bit = np.array(Image.open(self.trainfile)) self.dims = self.image_8bit.shape
def setUpClass(self): # pass mt.make() self.testfile = 'test.tif' self.trainfile = 'train.tif' self.downloadfile = 'TRA_000823_1720_COLOR.JP2' temp = np.ones((256,256),'uint8')*125 self.rows, self.cols = load_extension.getDims(self.testfile) test_image = Image.fromarray(temp) test_image.save(self.testfile) self.image_8bit = np.array(Image.open(self.testfile)) train_image = Image.fromarray(temp) train_image.save(self.trainfile) self.image_8bit = np.array(Image.open(self.trainfile)) self.dims = self.image_8bit.shape
def get_labeled_data(filename, training_file): """Read input-array (image) and label-images and return it as list of tuples. """ rows, cols = load_extension.getDims(filename) print rows, cols image = np.ones((rows,cols),'uint8') label_image = np.ones((rows,cols),'uint8') # x is a dummy to use as a form of error checking will return false on error x = load_extension.getImage(image, filename) x = load_extension.getTraining(label_image, filename, training_file) #Seperate Image and Label into blocks #test_blocks,blocks = create_image_blocks(768, 393,11543,rows,cols,image) #label_blocks, blocks = create_image_blocks(768, 393,11543,rows,cols,label_image) test_blocks,blocks = load4d(4096, 8, 8,rows,cols,image) label_blocks, blocks = load4d(4096, 8,8,rows,cols,label_image) #Used to Write image blocks to folder #or i in range(blocks): #im = Image.fromarray(test_blocks[i][i]) #im.save(str(i) +"label.tif") return test_blocks, label_blocks
def get_labeled_data(filename, training_file): """Read input-array (image) and label-images and return it as list of tuples. """ rows, cols = load_extension.getDims(filename) print rows, cols image = np.ones((rows, cols), 'uint8') label_image = np.ones((rows, cols), 'uint8') # x is a dummy to use as a form of error checking will return false on error x = load_extension.getImage(image, filename) x = load_extension.getTraining(label_image, filename, training_file) #Seperate Image and Label into blocks #test_blocks,blocks = create_image_blocks(768, 393,11543,rows,cols,image) #label_blocks, blocks = create_image_blocks(768, 393,11543,rows,cols,label_image) test_blocks, blocks = load4d(4096, 8, 8, rows, cols, image) label_blocks, blocks = load4d(4096, 8, 8, rows, cols, label_image) #Used to Write image blocks to folder #or i in range(blocks): #im = Image.fromarray(test_blocks[i][i]) #im.save(str(i) +"label.tif") return test_blocks, label_blocks
def getPredictionData(inputFile, block_size=32): #Load image using extension rows, cols = load_extension.getDims(inputFile) print rows, cols image = np.ones((rows, cols), 'uint8') # x is a dummy to use as a form of error checking will return false on error x = load_extension.getImage(image, inputFile) X = [] blocklist = [] for i in xrange(0,rows,block_size): for j in xrange(0,cols,block_size): try: X.append(image[i:i + block_size, j:j + block_size].reshape(1, block_size * block_size)) blocklist.append(image[i:i + block_size, j:j + block_size]) except ValueError: continue X = np.array(X).astype(np.float32) X = X.reshape(-1, 1, block_size, block_size) load_extension.getImage(image, inputFile) return X, image, blocklist
import load_extension 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])
def test_getImage(self): x = np.ones(le.getDims(self.filename), 'uint8') le.getImage(x, self.filename) self.image_8bit = np.array(Image.open(self.filename)) assert ((self.image_8bit == x).all(), True)
def test_getDims(self): # pil_dims = Image.open() assert(self.dims==le.getDims(self.filename), True)
def test_getPredictionData(self): x = cn.getPredictionData(self.testfile, block_size=32) rows, cols = load_extension.getDims(self.testfile) testrows, testcols = x[1].shape self.assertEqual(np.ndim(x[0]), 4) self.assertEqual((testrows, testcols), (rows, cols))
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 load_extension 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)