Example #1
0
def clipped_zoom(img, zoom_factor):
    # img : numpy.ndarray
    h, w, _ = img.shape
    # ceil crop height(= crop width)
    ch = int(np.ceil(h / zoom_factor))
    cw = int(np.ceil(w / zoom_factor))

    top = (h - ch) // 2
    left = (w - cw) // 2
    img = scizoom(img[top:top + ch, left:left + cw],
                  (zoom_factor, zoom_factor, 1),
                  order=1)

    # trim off any extra pixels
    trim_top = (img.shape[0] - h) // 2
    trim_left = (img.shape[1] - w) // 2
    # trim_top = (h - img.shape[0]) // 2
    # trim_left = (w - img.shape[1]) // 2

    if trim_top < 0 or trim_left < 0:
        # print 'h, w, zoom_factor, ch, cw, image.shape :', h, w, zoom_factor, ch, cw, img.shape
        # raise NotImplemented

        img = (np.clip(img, 0, 1) * 255).astype(np.uint8)
        img = PILImage.fromarray(img.squeeze(), mode='L')
        img = img.resize((w, h), PILImage.BOX)
        img = np.array(img, dtype=np.float32) / 255.

        trim_top = 0
        trim_left = 0

    img = img[trim_top:trim_top + h, trim_left:trim_left + w]

    return img
def clipped_zoom(img, zoom_factor):
    h = img.shape[0]
    # ceil crop height(= crop width)
    ch = int(np.ceil(h / zoom_factor))

    top = (h - ch) // 2
    img = scizoom(img[top:top + ch, top:top + ch], (zoom_factor, zoom_factor, 1), order=1)
    # trim off any extra pixels
    trim_top = (img.shape[0] - h) // 2

    return img[trim_top:trim_top + h, trim_top:trim_top + h]
Example #3
0
def clipped_zoom(img, zoom_factor):
    # clipping along the width dimension:
    ch0 = int(np.ceil(img.shape[0] / float(zoom_factor)))
    top0 = (img.shape[0] - ch0) // 2

    # clipping along the height dimension:
    ch1 = int(np.ceil(img.shape[1] / float(zoom_factor)))
    top1 = (img.shape[1] - ch1) // 2

    img = scizoom(img[top0:top0 + ch0, top1:top1 + ch1],
                  (zoom_factor, zoom_factor, 1),
                  order=1)

    return img
Example #4
0
def clipped_zoom(img, zoom_factor):
    h, w = img.shape[:2]
    # ceil crop height(= crop width)
    ch_h = int(np.ceil(h / float(zoom_factor)))
    ch_w = int(np.ceil(w / float(zoom_factor)))

    top = (h - ch_h) // 2
    left = (w - ch_w) // 2
    img = scizoom(img[top:top + ch_h, left:left + ch_w],
                  (zoom_factor, zoom_factor, 1),
                  order=1)
    # trim off any extra pixels
    trim_top = (img.shape[0] - h) // 2
    trim_left = (img.shape[1] - w) // 2

    return img[trim_top:trim_top + h, trim_left:trim_left + w]
Example #5
0
def clipped_zoom(img, zoom_factor):
    h = img.shape[0]
    w = img.shape[1]

    # ceil crop height(= crop width)
    ch = int(np.ceil(h / float(zoom_factor)))
    cw = int(np.ceil(w / float(zoom_factor)))

    top = (h - ch) // 2
    side = (w - cw) // 2

    img = scizoom(img[top:top + ch, side:side + cw],
                  (zoom_factor, zoom_factor, 1), order=1)
    # trim off any extra pixels
    trim_top = (img.shape[0] - h) // 2
    trim_side = (img.shape[1] - w) // 2

    return img[trim_top:trim_top + h, trim_side:trim_side + w]
Example #6
0
def clipped_zoom(img, zoom_factor):
    h = img.shape[0]
    w = img.shape[1]
    # ceil crop height(= crop width)
    ch = int(np.ceil(h / zoom_factor))
    cw = int(np.ceil(w / zoom_factor))

    top_h = (h - ch) // 2
    top_w = (w - cw) // 2

    img = scizoom(img[top_h:top_h + ch, top_w:top_w + cw],
                  (zoom_factor, zoom_factor, 1),
                  order=1)
    # trim off any extra pixels
    trim_top_h = (img.shape[0] - h) // 2
    trim_top_w = (img.shape[1] - w) // 2

    return img[trim_top_h:trim_top_h + h, trim_top_w:trim_top_w + w]