Ejemplo n.º 1
0
def reshape(width, height):
    global camera, windowsize
    glViewport(0, 0, width, height)
    camera.projection = tr.perspective(50.0, width / float(height), 2.0, 10.0)
    loc = glGetUniformLocation(program, "projectionMatrix")
    glUniformMatrix4fv(loc, 1, GL_FALSE, camera.projection)
    windowsize = (width, height)
Ejemplo n.º 2
0
def reshape(width, height):
    gl.glViewport(0, 0, width, height)
    projection = perspective(45.0, width / float(height), 2.0, 10.0)
    program['u_projection'] = projection
Ejemplo n.º 3
0
def reshape(width,height):
    global projection, view
    gl.glViewport(0, 0, width, height)
    projection = perspective( 45.0, width/float(height), 2.0, 10.0 )
    view = np.identity(4,dtype=np.float32)
    translate(view, 0,0,-5)
Ejemplo n.º 4
0
def reshape(width,height):
    gl.glViewport(0, 0, width, height)
    projection = perspective( 45.0, width/float(height), 2.0, 10.0 )
    program['projection'] = projection
Ejemplo n.º 5
0
def on_reshape(width, height):
    gl.glViewport(0, 0, width, height)
    u_projection[...] = perspective( 25.0, width/float(height), 2.0, 10.0 )
Ejemplo n.º 6
0
 def on_resize(self, width, height):
     gl.glViewport(0, 0, width, height)
     self.projection = perspective( 45.0, width/float(height), 2.0, 10.0 )
Ejemplo n.º 7
0
 def on_resize(self, event):
     width, height = event.size
     gl.glViewport(0, 0, width, height)
     self.projection = perspective(45.0, width / float(height), 2.0, 10.0)
     self.program.uniforms['u_projection'] = self.projection
Ejemplo n.º 8
0
 def on_resize(self, event):
     width, height = event.size
     gl.glViewport(0, 0, width, height)
     self.projection = perspective( 45.0, width/float(height), 2.0, 10.0 )
     self.program.uniforms['u_projection'] = self.projection
Ejemplo n.º 9
0
def on_reshape(width, height):
    gl.glViewport(0, 0, width, height)
    u_projection[...] = perspective(25.0, width / float(height), 2.0, 10.0)
Ejemplo n.º 10
0
def reshape(width,height):
    global u_projection
    gl.glViewport(0, 0, width, height)
    u_projection = perspective( 25.0, width/float(height), 2.0, 10.0 )
Ejemplo n.º 11
0
    def __call__(self, img):
        """Apply manipulations to image.
        Args:
            img (PIL Image): Image to be manipulated.
        Returns:
            PIL Image: Anchor Image (128x128)
            PIL Image: Manipulated Image (128x128)
        """
        cfg = self.config
        anchor = transforms.center_crop(img, 128).copy()

        # flipping
        if np.random.rand() < cfg["p_horizontal_flip"]:
            img = transforms.hflip(img)
        if np.random.rand() < cfg["p_vertical_flip"]:
            img = transforms.vflip(img)

        # perspective
        if "perspective_range" in cfg:
            width, height = img.size
            startpoints = np.array([(0, 0), (0, height), (width, height), (width, 0)])
            rho = np.random.randint(*cfg["perspective_range"], startpoints.shape)
            endpoints = startpoints + rho
            img = transforms.perspective(img, startpoints, endpoints)

        # affine
        if "affine" in cfg:
            scale = np.random.uniform(*cfg["affine"]["scale_range"])
            rotation = np.random.uniform(*cfg["affine"]["rotation_range"])
            translate = list(np.random.uniform(*cfg["affine"]["translation_range"], 2))
            img = transforms.affine(img, rotation, translate, scale, shear=0)

        # gamma
        if "gamma_range" in cfg:
            img = transforms.adjust_gamma(img, np.random.uniform(*cfg["gamma_range"]))

        # hue
        if "hue" in cfg:
            img = transforms.adjust_hue(img, np.random.uniform(*cfg["hue_range"]))

        # brightness
        if "brightness_range" in cfg:
            img = transforms.adjust_brightness(
                img, np.random.uniform(*cfg["brightness_range"])
            )

        # contrast
        if "contrast_range" in cfg:
            img = transforms.adjust_contrast(
                img, np.random.uniform(*cfg["contrast_range"])
            )

        if "p_global_hist" in cfg and np.random.rand() < cfg["p_global_hist"]:
            img = (exposure.equalize_hist(np.array(img)) * 255).astype(np.uint8)
            img = Image.fromarray(img)

        elif "p_local_hist" in cfg and np.random.rand() < cfg["p_local_hist"]:
            selem = disk(10)
            img = (rank.equalize(np.array(img), selem=selem) * 255).astype(np.uint8)
            img = Image.fromarray(img)

        if np.random.rand() < cfg["p_invert"]:
            img = ImageOps.invert(img)

        if "p_blur" in cfg and np.random.rand() < cfg["p_blur"]:
            img = img.filter(ImageFilter.GaussianBlur(radius=2))

        if "p_jpeg" in cfg and np.random.rand() < cfg["p_jpeg"]:
            buffer = io.BytesIO()
            img.save(buffer, "JPEG", quality=50)
            img = Image.open(buffer)

        if "p_noise" in cfg and np.random.rand() < cfg["p_noise"]:
            img = np.array(img)
            img = img + np.random.normal(loc=0, scale=16, size=img.shape)
            img = np.clip(img, 0, 255).astype(np.uint8)
            img = Image.fromarray(img)

        # grayscale
        if "grayscale" in cfg:
            img = transforms.to_grayscale(img, num_output_channels=cfg["grayscale"])
            anchor = transforms.to_grayscale(
                anchor, num_output_channels=cfg["grayscale"]
            )

        img = transforms.center_crop(img, 128)
        return anchor, img
Ejemplo n.º 12
0
 def on_resize(self, width, height):
     gl.glViewport(0, 0, width, height)
     self.projection = perspective(45.0, width / float(height), 2.0, 10.0)