コード例 #1
0
 def split_in_four(self, im):
     half = self.size[0]/2, self.size[1]/2
     top_left = image.crop(im, (0, 0, half[0], half[1]))
     top_right = image.crop(im, (half[0], 0, half[0], half[1]))
     bottom_left = image.crop(im, (0, half[1], half[0], half[1]))
     bottom_right = image.crop(im, (half[0], half[1], half[0], half[1]))
     return top_left, top_right, bottom_left, bottom_right
コード例 #2
0
async def crop_local(data: CropImage):
    """
    Crop the specified base64 image. Image must be in the form of a base64 string, regardless of format. See here for supported formats: https://tinyurl.com/yymmmpwk

     * Variable `url` specifies the remote URL to pull the image from.
     * Variables `x` and `y` specify the origin point of the crop. 
     * The variables `width` and `height` specify the width and height of the output crop. 
     * The `image_format` variable can be any output format supported by Pillow. See here: https://tinyurl.com/yymmmpwk
     * Output is a an image file. Defaults to JPEG.
    """
    b64_image = data.get('base64_image')

    if get_b64_size(b64_image) > 20971520:
        raise HTTPException(status_code=413, detail="Content is too large.")

    height = data.get('height')
    width = data.get('width')
    x = data.get('x')
    y = data.get('y')
    image_format = data.get('image_format')

    image_buffer = BytesIO()
    content = BytesIO(base64.b64decode(b64_image))
    content.seek(0)

    image_buffer = crop(content, x, y, width, height, image_format)

    content.close()

    return Response(image_buffer.getvalue(), status_code=200)
コード例 #3
0
async def crop_remote(url: str = 'https://s.gravatar.com/avatar/434d67e1ebc4109956d035077ef5adb8', height: int = 250, width: int = 250, x: int = 0, y: int = 0, image_format: str = 'JPEG'):
    """
    Crops an image at the specified URL. 

     * Variable `url` specifies the remote URL to pull the image from.
     * Variables `x` and `y` specify the origin point of the crop. 
     * The variables `width` and `height` specify the width and height of the output crop. 
     * The `image_format` variable can be any output format supported by Pillow. See here: https://tinyurl.com/yymmmpwk
     * Output is a an image file. Defaults to JPEG.
    """
    response = requests.get(url)
    if response.status_code != 200:
        raise HTTPException(status_code=response.status_code,
                            detail=f'Server returned error {response.status_code}.')

    if len(response.content) > 20971520:
        raise HTTPException(status_code=413, detail="Content is too large.")

    print(image_format)

    content = BytesIO(response.content)
    content.seek(0)

    image_buffer = crop(content, x, y, width, height, image_format)

    content.close()

    return Response(image_buffer.getvalue(), status_code=200)
コード例 #4
0
 def split_into(self, im, count):
     if type(count) not in (list, tuple):
         count = (count, count)
     box_w, box_h = self.size[0]/count[0], self.size[1]/count[1]
     images = []
     for x in range(count[0]):
         for y in range(count[1]):
             box = (box_w * x, box_h * y, box_w-1, box_h-1)
             images.append(image.crop(im, box))
     return images
コード例 #5
0
    def add_patch(self, original_image_filepath, coordinate):
        if not self.user_exists():
            self.create_user()

        basename = os.path.basename(original_image_filepath)
        patch_path = os.path.join(self.patch_dirpath, basename)

        image = imread(original_image_filepath)
        patch = crop(image, coordinate)

        imsave(patch_path, patch)
コード例 #6
0
def imgCrop(image, cropBox, boxScale=1):
    # Crop a PIL image with the provided box [x(left), y(upper), w(width), h(height)]

    # Calculate scale factors
    xDelta = max(cropBox[2] * (boxScale - 1), 0)
    yDelta = max(cropBox[3] * (boxScale - 1), 0)

    # Convert cv box to PIL box [left, upper, right, lower]
    PIL_box = [
        cropBox[0] - xDelta, cropBox[1] - yDelta,
        cropBox[0] + cropBox[2] + xDelta, cropBox[1] + cropBox[3] + yDelta
    ]

    return image.crop(PIL_box)
コード例 #7
0
ファイル: webdriver.py プロジェクト: GelLiNN/tagcompare
def screenshot_element(driver, element, output_path):
    """Take a screenshot of a specific webelement
    """
    size = element.size
    location = element.location

    left = location['x']
    top = location['y']
    right = location['x'] + size['width']
    bottom = location['y'] + size['height']
    cropbox = (left, top, right, bottom)

    f = _screenshot(driver, output_path)
    img = image.crop(f, cropbox)
    return img
コード例 #8
0
def screenshot_element(driver, element, output_path):
    """Take a screenshot of a specific webelement
    """
    size = element.size
    location = element.location

    left = location['x']
    top = location['y']
    right = location['x'] + size['width']
    bottom = location['y'] + size['height']
    cropbox = (left, top, right, bottom)

    f = _screenshot(driver, output_path)
    img = image.crop(f, cropbox)
    return img
コード例 #9
0
ファイル: learning.py プロジェクト: rmcgibbo/autogert
def predict(clf, boundaries, img=None, align_template=None):
    if isinstance(img, basestring):
        raw_img = io.imread(img)
    elif isinstance(img, np.ndarray):
        raw_img = img
    else:
        raise TypeError()

    if align_template is None:
        aligned_img = raw_img
    else:
        aligned_img = align_fft(raw_img, align_template)

    cropped_img = crop(aligned_img, boundaries)
    binarized_img = preprocess(cropped_img)
    chars = split(binarized_img)

    # this gets an array of ints
    predictions = clf.predict(np.array([c.reshape(-1) for c in chars]))
    # make into a string
    prediction = ''.join([str(p) for p in predictions])
    return prediction, binarized_img, chars
コード例 #10
0
ファイル: __init__.py プロジェクト: HULKs/HULKsCodeRelease
def image(index):
    if index < 0:
        return flask.make_response('index cannot be negative', 404)
    if index >= len(app.config['annotations'].keys()):
        return flask.make_response('index cannot be larger than amount of images', 404)

    image = sorted(app.config['annotations'].keys())[index]

    image = img.read(image)
    image = img.convert_color_space(
        image,
        source_color_space=app.config['arguments']['color_space'],
        target_color_space='RGB',
    )

    if 'crop' in flask.request.args:
        try:
            center_x = float(flask.request.args['centerX'])
            center_y = float(flask.request.args['centerY'])
            radius = float(flask.request.args['radius'])
        except (KeyError, ValueError):
            return flask.make_response('centerX, centerY, or radius missing or malformed', 404)

        upper_left = np.array([[center_x - radius],
                               [center_y - radius]])
        lower_right = np.array([[center_x + radius],
                                [center_y + radius]])

        image = img.crop(
            image,
            upper_left,
            lower_right,
            [
                app.config['arguments']['default_gray'],
                app.config['arguments']['default_gray'],
                app.config['arguments']['default_gray'],
            ],
        )

    if 'scale' in flask.request.args:
        try:
            scale_width = int(
                flask.request.args['width']) if 'width' in flask.request.args else None
            scale_height = int(
                flask.request.args['height']) if 'height' in flask.request.args else None
        except ValueError:
            return flask.make_response('width or height malformed', 404)

        if scale_width is None and scale_height is None:
            return flask.make_response('width and height missing', 404)

        if scale_width is None:
            scale_width = int(scale_height / image.shape[0] * image.shape[1])
        if scale_height is None:
            scale_height = int(scale_width / image.shape[1] * image.shape[0])

        size = np.array([[scale_width],
                         [scale_height]])

        image = img.resize(image, size)

    response = flask.make_response(img.encode(image, 'png'))
    response.headers['Content-Type'] = 'image/png'
    return response
コード例 #11
0
ファイル: allPythonContent.py プロジェクト: shobrook/pyreco
def splitRight(image):
    widthImg, heightImg = image.size

    return image.crop((widthImg / 2, 0, widthImg, heightImg))
コード例 #12
0
ファイル: allPythonContent.py プロジェクト: shobrook/pyreco
def splitLeft(image):
    widthImg, heightImg = image.size

    return image.crop((0, 0, widthImg / 2, heightImg))
コード例 #13
0
ファイル: allPythonContent.py プロジェクト: Mondego/pyreco
def splitRight(image):
    widthImg, heightImg = image.size
    
    return image.crop((widthImg / 2, 0, widthImg, heightImg))
コード例 #14
0
ファイル: allPythonContent.py プロジェクト: Mondego/pyreco
def splitLeft(image):
    widthImg, heightImg = image.size
    
    return image.crop((0, 0, widthImg / 2, heightImg))
コード例 #15
0
 def generate_patch(self):
     # create patch
     patch = crop(data.lena(), (15, 15))
     self.lena_patch_path = os.path.join(root_user_data, "test",
                                         patch_dirname, lena_filename)
     imsave(self.lena_patch_path, patch)