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 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 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
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
Example #5
0
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
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")
 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)
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
Example #9
0
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
Example #10
0
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")