Esempio n. 1
0
def cropImage(fileName, index, count, dim, loc = (0,0)):
	with Image.open(fileName) as img:
		x = (index % count) * dim[0]
		y = (index // count) * dim[1]
		part = offset(img, -x, -y).crop((0,0,dim[0],dim[1]))
	whole_img = Image.new("RGBA", (16,32), (0,0,0,0))
	whole_img.paste(part, loc, part)
	return whole_img
Esempio n. 2
0
def cropImage(fileName, index, count, dim, loc = (0,0)):
	with Image.open(fileName) as img:
		x = (index % count) * dim[0]
		y = (index // count) * dim[1]
		part = offset(img, -x, -y).crop((0,0,dim[0],dim[1]))
	whole_img = Image.new("RGBA", (16,32), (0,0,0,0))
	whole_img.paste(part, loc, part)
	return whole_img
Esempio n. 3
0
 def set_photo(self):
     # Sort out the image
     tn = self.images[self.img_index[self.label_index][1]].copy()
     # Offset the image
     tn = offset(tn, self.global_x_offset, self.global_y_offset)
     draw = ImageDraw.Draw(tn, 'RGBA')
     draw.rectangle(self.square, (255, 0, 0, 125))
     del draw
     tn.thumbnail((self.bounding_dimension, self.bounding_dimension), Image.ANTIALIAS)
     self.photo = ImageTk.PhotoImage(tn)
Esempio n. 4
0
def cropImg(img, location, defaultSize=(16, 16), objectSize=(16, 16), resize=False, displacement=(0, 0)):
    row = int(img.width / (defaultSize[0]))
    x = (location % row) * defaultSize[0]
    y = (location // row) * defaultSize[1]
    image = offset(img, -x, -y).crop((0, 0, objectSize[0], objectSize[1]))

    if resize:
        base = Image.new("RGBA", (16, 32), (0, 0, 0, 0))
        base.paste(image, displacement, image)
        image = base
    return image
Esempio n. 5
0
def cropImg(img,
            location,
            defaultSize=(16, 16),
            objectSize=(16, 16),
            resize=False,
            displacement=(0, 0)):
    row = int(img.width / (defaultSize[0]))
    x = (location % row) * defaultSize[0]
    y = (location // row) * defaultSize[1]
    image = offset(img, -x, -y).crop((0, 0, objectSize[0], objectSize[1]))

    if resize:
        base = Image.new("RGBA", (16, 32), (0, 0, 0, 0))
        base.paste(image, displacement, image)
        image = base
    return image
Esempio n. 6
0
    def apply_calibration(self):
        """Apply calibration to all images."""
        # create calibrated dir
        if not os.path.exists(self.calibrated_folder):
            os.makedirs(self.calibrated_folder)

        for j in glob.glob(os.path.join(self.region_folder, "*.jpg")):
            filename = os.path.basename(j)
            time = filename.split("_")
            for t in time:
                if t.endswith(".jpg"):
                    time = t.strip(".jpg")
                    break

            if time in self.calibration:
                img = Image.open(j)
                img = offset(img, self.calibration[time][0], self.calibration[time][1])
                img.save(os.path.join(self.calibrated_folder, filename), "jpeg")
Esempio n. 7
0
def cropImg(img, location, defaultSize=(4, 4), objectSize=(4, 4)):
    row = int(img.width / (4*defaultSize[0]))
    x = (location % row) * 4 * defaultSize[0]
    y = (location // row) * 4 * defaultSize[1]
    return offset(img, -x, -y).crop((0, 0, 4*objectSize[0], 4*objectSize[1]))
Esempio n. 8
0
def cropImg(img, location, size, tileSize):
    y = (location // size[0]) * tileSize[1]
    x = (location % size[0]) * tileSize[0]
    return offset(img, -x, -y).crop((0, 0, tileSize[0], tileSize[1]))
Esempio n. 9
0
def cropImg(img, location, size, tileSize):
    y = (location//size[0]) * tileSize[1]
    x = (location % size[0]) * tileSize[0]
    return offset(img, -x, -y).crop((0, 0, tileSize[0], tileSize[1]))
Esempio n. 10
0
def cropImg(img, location, defaultSize=(4, 4), objectSize=(4, 4)):
    row = int(img.width / (4 * defaultSize[0]))
    x = (location % row) * 4 * defaultSize[0]
    y = (location // row) * 4 * defaultSize[1]
    return offset(img, -x, -y).crop(
        (0, 0, 4 * objectSize[0], 4 * objectSize[1]))
Esempio n. 11
0
    for i in range(9):
        j = (i + 9) % 18
        x_angle = angles[i]
        y_angle = angles[j]

        c = cos(x_angle)
        s = sin(x_angle)
        d = box_width / 2.
        d /= meters

        d = 0 # DELETEME

        dx = int(round(c*d))
        dy = int(round(s*d))

        fxp = (offset(Image.fromarray(responses[i]), dx, dy))
        fxm = (offset(Image.fromarray(responses[i]), -dx, -dy))
        fyp = (offset(Image.fromarray(responses[j]), -dy, dx))
        fym = (offset(Image.fromarray(responses[j]), dy, -dx))

        score = np.sort(np.stack([fxp, fxm, fyp, fym]), axis=0)[3]
        scores.append(score)

    subplot(121)
    imshow(np.max(scores, axis=0))
    gray()
    colorbar()
    subplot(122)
    imshow(a)
    colorbar()
    show()