def test_getTraining(self): test = np.array(Image.open(self.filename), 'uint8') train = np.array(Image.open(self.filename), 'uint8') np.bitwise_xor(test,train,test) image = np.ones(test.shape,test.dtype) le.getTraining(image,self.filename, self.filename) assert((test == image).all(), True)
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 get_labeled_data(filename, training_file): """Read input-array (image) and label-images and return it as list of tuples. """ rows,cols = load_extension.get_dims(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(24,11543,12576,rows,cols,image) label_blocks, blocks = create_image_blocks(24,11543,12576,rows,cols,label_image) #Used to Write image blocks to folder # for i in range(blocks): # im = Image.fromarray(test_blocks[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