Пример #1
0
def train_lbp():
    train_dir = "/home/gast/ImageHashing/face_train/"
    suffix = ".png"
    size = 200

    train = []
    for fn in sorted(os.listdir(train_dir)):
        if fn.endswith(suffix):
            rgb = Image.load(train_dir + fn)
            gray = Image.rgb2gray(rgb)
            resized = Image.resize(gray,size)
            img = Image.gray2real(resized)
            lbps = local_binary_pattern(img,3,24)
            #print(flatten(lbps))
            #print(len(flatten(lbps)))
            train.append(flatten(lbps))
            #print(lbps)

    pca = PCA(n_components=100)
    #print(len(train))
    #print(len(train[0]))
    train_np = np.array(train)
    #print(train_np.shape)
    pca.fit(train_np)
    return pca
Пример #2
0
def train_eigen():
    # train_dir = "/home/gast/ImageHashing/face_train/"
    train_dir = "/home/gast/ImageHashing/FEC/fec_images_autoadjust/"
    suffix = ".png"
    size = 200

    train = []
    for fn in sorted(os.listdir(train_dir)):
        if fn.endswith(suffix):
            rgb = Image.load(train_dir + fn)
            gray = Image.rgb2gray(rgb)
            resized = Image.resize(gray,size)
            img = Image.gray2real(resized)
            #lbps = list(flatten(Lbp.real_hash(img)))
            img_flat = list(flatten(img))
            # print(len(flatten(lbps)))
            train.append(img_flat)
            #print(lbps)

    t = np.array(train)
    #print("len of train"+str(t.shape))
    pca = PCA(n_components=100)
    pca.fit(train)

    return pca
Пример #3
0
    def __init__(self, x, y, menu):
        self.pos = (x, y)
        self.menu = menu
        self.rect = Button.OFF_IMAGE_RECT[self.menu]
        self.image = Image.load("IMAGE/TitleMenu.png")
        self.mouse_point = None

        if (Button.SELECT_WAV == None):
            Button.SELECT_WAV = load_wav("SOUND/stomp.wav")

        if (Button.DES_IMAGE == None):
            Button.DES_IMAGE = Image.load("IMAGE/Description.png")

        if (Button.DES_ON_WAV == None or Button.DES_OFF_WAV == None):
            Button.DES_ON_WAV = load_wav("SOUND/description_on.wav")
            Button.DES_OFF_WAV = load_wav("SOUND/description_off.wav")
Пример #4
0
    def __init__(self, left, bottom, width, x, y, menu):
        self.image = Image.load("IMAGE/TitleMenu.png")
        self.src_rect = (self.left, self.bottom, self.width,
                         self.height) = (left, bottom, width, 90)
        self.pos = (x, y)
        self.menu = menu
        self.mouse_point = None

        if (Button.SELECT_WAV == None):
            Button.SELECT_WAV = load_wav("SOUND/stomp.wav")
Пример #5
0
def load():
	global sprite_image

	if (sprite_image is None):
		sprite_image = Image.load("IMAGE/Sprite.png")

		with open("JSON/ObjectRect.json") as file:
			data = json.load(file)

			for name in data:
				#print(name)
				sprite_rects[name] = tuple(data[name])
def TurtlePainting(Image,filtervalue):
    pix=Image.load()
    #turtle.speed(0)
    turtle.tracer(0)
    turtle.penup()
    width=Image.size[0]
    height=Image.size[1]
    turtle.setup(width,height+30,-turtle.window_width(),-turtle.window_height())
    for i in range(height):
        for j in range(width):
            if pix[j,i][0]<=filtervalue:
                turtle.setpos(j-turtle.window_width()/2,-i+turtle.window_height()/2-10)
                turtle.dot(8)
Пример #7
0
	def __init__(self):
		self.pos = (100, 300)
		self.delta = (0, 0)
		self.fidx = 0
		self.time = 0
		self.prev_state = None
		self.state = Mario.RIGHT_IDLE
		self.FPS = 7
		self.image = Image.load("IMAGE/Mario.png")
		self.is_collide = False

		if (Mario.JUMP_WAV == None):
			Mario.JUMP_WAV = load_wav("SOUND/jump.wav")
		if (Mario.LIFE_LOST_WAV == None):
			Mario.LIFE_LOST_WAV = load_wav("SOUND/life lost.wav")
			Mario.LIFE_LOST_WAV.set_volume(50)
Пример #8
0
def train_lbp():
    train_dir = "/home/gast/ImageHashing/face_train/"
    suffix = ".png"
    size = 200

    train = []
    for fn in sorted(os.listdir(train_dir)):
        if fn.endswith(suffix):
            rgb = Image.load(train_dir + fn)
            gray = Image.rgb2gray(rgb)
            resized = Image.resize(gray,size)
            img = Image.gray2real(resized)
            lbps = list(flatten(Lbp.real_hash(img)))
            # print(len(flatten(lbps)))
            train.append(lbps)
            #print(lbps)

    pca = PCA(n_components=500)
    pca.fit(train)

    return pca
Пример #9
0
def get_width_height(img_name):
    Image.load(img_name)
    x, y = img.size
    return (x, y)
Пример #10
0
    cameraDir = cameraUP.cross(gaze.vector).normalized()

    #compute field of view
    ratio =  float (image.height)/float(image.width)

    #45 degree field of view
    fieldRad = math.pi * (float(45) / float(2) / float(180))


    #get world dimensions
    width = (math.tan(fieldRad) * 2.0)
    height = ratio * math.tan(fieldRad) * 2.0
    pixelWidth = width / (image.width - 1)
    pixelHeight = height / (image.height - 1)
    
   #begin ray tracing
    for y in range(image.height):
        for x in range(image.width):
            xOffset = cameraUP*(x * pixelWidth - (width/2))
            yOffset = cameraDir*(y * pixelHeight - (height/2))
            #if x is 1 and y is 1:
             #   print xOffset.x, xOffset.y, xOffset.z
             #   print yOffset.x, yOffset.y, yOffset.z
            ray = reverseRay(gaze.point, gaze.vector + xOffset + yOffset)
            color = world.rayColor(ray)
            image.load(x,y,*color)

    print 'All done, look in this directory for ' + image.name


    image.toFile()
Пример #11
0
import Image

imgfile = '~/Challenge/oxygen.png'

oxyim = Image.load(imgfile)
pix_val = list(oxyim.getdata())
pix_mat = []
pix_ind = 0

for i in range(95):
    pix_matr.append([])
    for j in range(629):
        pix_matr[i].append(pix_val[pix_ind])
        pix_ind += 1

for i in range(40,55):
    print "Row "+str(i)
    for j in range(40):
        print pix_matr[i][j]
# first repeating line is 43

testrow = pix_matr[43]
for i in range(0, 608, 7):
    output.append(testrow[i][0])

decoded = ''
for i in range(len(output)):
    decoded += chr(output[i])
print decoded

recode = [105, 110, 116, 101, 103, 114, 105, 116, 121]
Пример #12
0
def compute_hash(filename):        
    re = 64
    if args.r != None:
        re = args.r[0]
    rgb = Image.load(filename)
    gray = Image.rgb2gray(rgb)
    gray_pp = gray
    if(args.pp != None and args.pp[0] == 'gb'):
        gray_pp = Image.gauss_blur(gray,2)
    if(args.pp != None and args.pp[0] == 'tt'):
        gray_pp = tt_pipeline(gray)
    resized = Image.resize(gray_pp,re)
    img = Image.gray2real(resized)
    hash_result = []
    if(args.cm != None and args.cm[0] == "ham"):
        if(args.hm != None):
            if args.hm[0] == "ah":
                img = Image.resize(img,8)
                hash_result = Average.bin_hash(img)
            if args.hm[0] == "dh":
                img = Image.resize2(img,9,8)
                hash_result = Difference.bin_hash(img)
            if args.hm[0] == "dct":
                hash_result = Dct.bin_hash(img,8,8)
            if args.hm[0] == "zh":
                hash_result = Zernike.bin_hash(img,0,8)
            if args.hm[0] == "pzh":
                hash_result = PseudoZernike.bin_hash(img,0,11)
            if args.hm[0] == "rash":
                print("Radon Hash can only output reals")
            if args.hm[0] == "wu":
                input_wu = Image.resize(gray,384)
                hash_result = Wu.bin_hash(input_wu)
    else:
        if(args.hm != None):
            if args.hm[0] == "ah":
                img = Image.resize(img,8)
                hash_result = Average.real_hash(img)
            if args.hm[0] == "dh":
                img = Image.resize2(img,9,8)
                hash_result = Difference.real_hash(img)
            if args.hm[0] == "dct":
                #img1 = exposure.equalize_hist(img)
                hash_result = Dct.real_hash(img,8,8)
            if args.hm[0] == "zh":
                hash_result = Zernike.real_hash(img,0,12)
            if args.hm[0] == "pzh":
                hash_result = PseudoZernike.real_hash(img,0,11)
            if args.hm[0] == "lbp":                
                hash_result = Lbp.real_hash(img)
            if args.hm[0] == "lbp1":
                # im = Image.resize2(gray,220,220)
                im = Image.resize(gray,220)
                im2 = Image.gray2real(im)
                img_blur = Image.gauss_blur(im2,2)
                hash_result = Lbp.real_hash(img_blur)
                #hash_result = Lbp.bin_hash(img_blur)
            #if args.hm[0] == "lbp_pca":
            #    pcad = pickle.load(open("lbp_pca_train.p", "rb" ))
            #    hash_result = Lbp.pca_hash(img,pcad)
                #print(len(hash_result))
            #if args.hm[0] == "eigen":
            #    model = pickle.load(open("eigen_model.p", "rb" ))
            #    hash_result = eigen.transform_eigen(img,model)
            if args.hm[0] == "fft":
                hash_result = Fft.fft_hash(img)
            if args.hm[0] == "rash":
                img = Image.resize(img,63)
                hash_result = Radon.real_hash(img)
    # default
    if hash_result == []:
        print("default")
        hash_result = Dct.real_hash(img,8,8)
    return hash_result
Пример #13
0
 def __init__(self, file, player=None):
     self.image = Image.load(file)
     self.mario = player
     self.stage_level = 1
Пример #14
0
import Image
import numpy as np

im = Image.load('nr33.jpg')
im = im.convert('L')

arr = np.fromiter(iter(im.getdata()), np.uint8)
arr.resize(im.height, im.width)

arr ^= 0xFF  # invert
inverted_im = Image.fromarray(arr, mode='L')
inverted_im.show()
Пример #15
0
import numpy as np
import matplotlib.pyplot as plt

from skimage import data
from skimage.feature import match_template

import Image

needle_rgb = Image.load("90a_scan.png")
needle = Image.rgb2gray(needle_rgb)

haystack_rgb = Image.load("90a_camera.jpg")
haystack = Image.rgb2gray(haystack_rgb)

result = match_template(haystack, needle)
ij = np.unravel_index(np.argmax(result), result.shape)
x, y = ij[::-1]

fig, (ax1, ax2, ax3) = plt.subplots(ncols=3, figsize=(8, 3))

ax1.imshow(needle)
ax1.set_axis_off()
ax1.set_title('template')

ax2.imshow(haystack)
ax2.set_axis_off()
ax2.set_title('image')
# highlight matched region
hcoin, wcoin = needle.shape
rect = plt.Rectangle((x, y), wcoin, hcoin, edgecolor='r', facecolor='none')
ax2.add_patch(rect)