當前位置: 首頁>>代碼示例>>Python>>正文


Python transform.rescale方法代碼示例

本文整理匯總了Python中skimage.transform.rescale方法的典型用法代碼示例。如果您正苦於以下問題:Python transform.rescale方法的具體用法?Python transform.rescale怎麽用?Python transform.rescale使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在skimage.transform的用法示例。


在下文中一共展示了transform.rescale方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: image_dump_handler

# 需要導入模塊: from skimage import transform [as 別名]
# 或者: from skimage.transform import rescale [as 別名]
def image_dump_handler(out_folder, scale_factor=1.):
    def _fn(losses, inputs, outputs, kwargs):
        if kwargs['iter'] != 1:
            return
        A_real = inputs[0].data.cpu().numpy()
        B_real = inputs[1].data.cpu().numpy()
        atob, atob_btoa, btoa, btoa_atob = \
            [elem.data.cpu().numpy() for elem in outputs.values()]
        outs_np = [A_real, atob, atob_btoa, B_real, btoa, btoa_atob]
        # determine # of channels
        n_channels = outs_np[0].shape[1]
        w, h = outs_np[0].shape[-1], outs_np[0].shape[-2]
        # possible that A_real.bs != B_real.bs
        bs = np.min([outs_np[0].shape[0], outs_np[3].shape[0]])
        grid = np.zeros((h*bs, w*6, 3))
        for j in range(bs):
            for i in range(6):
                n_channels = outs_np[i][j].shape[0]
                img_to_write = convert_to_rgb(outs_np[i][j], is_grayscale=False)
                grid[j*h:(j+1)*h, i*w:(i+1)*w, :] = img_to_write
        imsave(arr=rescale(grid, scale=scale_factor),
               fname="%s/%i_%s.png" % (out_folder, kwargs['epoch'], kwargs['mode']))
    return _fn 
開發者ID:joelmoniz,項目名稱:DepthNets,代碼行數:25,代碼來源:task_launcher_faceswap.py

示例2: main

# 需要導入模塊: from skimage import transform [as 別名]
# 或者: from skimage.transform import rescale [as 別名]
def main():
  parser = argparse.ArgumentParser(
    formatter_class=argparse.ArgumentDefaultsHelpFormatter)

  parser.add_argument("--image_path",
                      help="path for image to run inference",
                      default="~/demo/data/mscoco_fns/val2014/COCO_val2014_000000301397.jpg")

  args = parser.parse_args()

  args.image_path = os.path.expanduser(args.image_path)

  # Read the image
  image = skimage.io.imread(args.image_path, plugin='imageio')
  image = rescale(image, 2.0, anti_aliasing=False)
  image = img_as_ubyte(image)

  data = json.dumps({"signature_name": "predict", "instances": image.tolist()})
  headers = {"content-type": "application/json"}

  response = requests.post(SERVER_URL, data=data, headers=headers)
  response.raise_for_status()
  predictions = response.json()["predictions"]

  display_ori(image, predictions[0]) 
開發者ID:lambdal,項目名稱:lambda-deep-learning-demo,代碼行數:27,代碼來源:object_detection_client.py

示例3: resize_img_with_max_size

# 需要導入模塊: from skimage import transform [as 別名]
# 或者: from skimage.transform import rescale [as 別名]
def resize_img_with_max_size(img, max_size=500*500):
    """Resize image with max size (height x width)"""
    from skimage.transform import rescale
    height, width = img.shape[:2]
    scale = max_size / (height * width)
    resizing_scale = 1
    if scale < 1:
        resizing_scale = np.sqrt(scale)
        img = rescale(img, resizing_scale, preserve_range=True)
        img = img.astype(np.uint8)
    return img, resizing_scale


# -----------------------------------------------------------------------------
# Chainer Util
# ----------------------------------------------------------------------------- 
開發者ID:oyam,項目名稱:Semantic-Segmentation-using-Adversarial-Networks,代碼行數:18,代碼來源:utils.py

示例4: test_upsample

# 需要導入模塊: from skimage import transform [as 別名]
# 或者: from skimage.transform import rescale [as 別名]
def test_upsample(self):
        h, w = 5, 5
        scale = 2

        mat = np.random.rand(h, w).astype('float32')
        inp = self.make_variable(mat)
        inp = tf.reshape(inp, [1, h, w, 1])

        output = BilinearUpSample('upsample', inp, scale)
        res = self.run_variable(output)

        from skimage.transform import rescale
        res2 = rescale(mat, scale)

        diff = np.abs(res2 - res[0,:,:,0])

        # not equivalent to rescale on edge
        diff[0,:] = 0
        diff[:,0] = 0
        if not diff.max() < 1e-4:
            import IPython;
            IPython.embed(config=IPython.terminal.ipapp.load_default_config())
        self.assertTrue(diff.max() < 1e-4) 
開發者ID:anonymous-author1,項目名稱:DDRL,代碼行數:25,代碼來源:pool.py

示例5: new_crap_AG_SP

# 需要導入模塊: from skimage import transform [as 別名]
# 或者: from skimage.transform import rescale [as 別名]
def new_crap_AG_SP(x, scale=4, upsample=False):
    xn = np.array(x)
    xorig_max = xn.max()
    xn = xn.astype(np.float32)
    xn /= float(np.iinfo(np.uint8).max)

    lvar = filters.gaussian(xn, sigma=5) + 1e-10
    xn = random_noise(xn, mode='localvar', local_vars=lvar*0.5)

    xn = random_noise(xn, mode='salt', amount=0.005)
    xn = random_noise(xn, mode='pepper', amount=0.005)

    new_max = xn.max()
    x = xn
    if new_max > 0:
        xn /= new_max
    xn *= xorig_max
    multichannel = len(x.shape) > 2

    xn = rescale(xn, scale=1/scale, order=1, multichannel=multichannel)
    return PIL.Image.fromarray(xn.astype(np.uint8)) 
開發者ID:BPHO-Salk,項目名稱:PSSR,代碼行數:23,代碼來源:crappifiers.py

示例6: new_crap

# 需要導入模塊: from skimage import transform [as 別名]
# 或者: from skimage.transform import rescale [as 別名]
def new_crap(x, scale=4, upsample=False):
    xn = np.array(x)
    xorig_max = xn.max()
    xn = xn.astype(np.float32)
    xn /= float(np.iinfo(np.uint8).max)

    xn = random_noise(xn, mode='salt', amount=0.005)
    xn = random_noise(xn, mode='pepper', amount=0.005)
    lvar = filters.gaussian(xn, sigma=5) + 1e-10
    xn = random_noise(xn, mode='localvar', local_vars=lvar*0.5)
    new_max = xn.max()
    x = xn
    if new_max > 0:
        xn /= new_max
    xn *= xorig_max
    multichannel = len(x.shape) > 2
    x = rescale(x, scale=1/scale, order=1, multichannel=multichannel)
    return PIL.Image.fromarray(x.astype(np.uint8)) 
開發者ID:BPHO-Salk,項目名稱:PSSR,代碼行數:20,代碼來源:crappifiers.py

示例7: fluo_SP_AG_D_sameas_preprint_rescale

# 需要導入模塊: from skimage import transform [as 別名]
# 或者: from skimage.transform import rescale [as 別名]
def fluo_SP_AG_D_sameas_preprint_rescale(x, scale=4, upsample=False):
    xn = np.array(x)
    xorig_max = xn.max()
    xn = xn.astype(np.float32)
    xn /= float(np.iinfo(np.uint8).max)
    xn = random_noise(xn, mode='salt', amount=0.005)
    xn = random_noise(xn, mode='pepper', amount=0.005)
    lvar = filters.gaussian(xn, sigma=5) + 1e-10
    xn = random_noise(xn, mode='localvar', local_vars=lvar*0.5)
    new_max = xn.max()
    x = xn
    if new_max > 0:
        xn /= new_max
    xn *= xorig_max
    multichannel = len(x.shape) > 2
    x_down = rescale(x, scale=1/scale, order=1, multichannel=multichannel)
    return PIL.Image.fromarray(x_down.astype(np.uint8)) 
開發者ID:BPHO-Salk,項目名稱:PSSR,代碼行數:19,代碼來源:crappifiers.py

示例8: test_BilinearUpSample

# 需要導入模塊: from skimage import transform [as 別名]
# 或者: from skimage.transform import rescale [as 別名]
def test_BilinearUpSample(self):
        h, w = 12, 12
        scale = 2

        mat = np.random.rand(h, w).astype('float32')
        inp = self.make_variable(mat)
        inp = tf.reshape(inp, [1, h, w, 1])

        output = BilinearUpSample(inp, scale)
        res = self.run_variable(output)[0, :, :, 0]

        from skimage.transform import rescale
        res2 = rescale(mat, scale, mode='edge')

        diff = np.abs(res2 - res)

        # if not diff.max() < 1e-4:
        #     import IPython
        #     IPython.embed(config=IPython.terminal.ipapp.load_default_config())
        self.assertTrue(diff.max() < 1e-4, diff.max()) 
開發者ID:microsoft,項目名稱:petridishnn,代碼行數:22,代碼來源:pool.py

示例9: test_upsample

# 需要導入模塊: from skimage import transform [as 別名]
# 或者: from skimage.transform import rescale [as 別名]
def test_upsample(self):
        h, w = 5, 5
        scale = 2

        mat = np.random.rand(h, w).astype('float32')
        inp = self.make_variable(mat)
        inp = tf.reshape(inp, [1, h, w, 1])

        output = BilinearUpSample('upsample', inp, scale)
        res = self.run_variable(output)[0,:,:,0]

        from skimage.transform import rescale
        res2 = rescale(mat, scale)

        diff = np.abs(res2 - res)

        # not equivalent to rescale on edge?
        diff[0,:] = 0
        diff[:,0] = 0
        if not diff.max() < 1e-4:
            import IPython;
            IPython.embed(config=IPython.terminal.ipapp.load_default_config())
        self.assertTrue(diff.max() < 1e-4) 
開發者ID:czhu95,項目名稱:ternarynet,代碼行數:25,代碼來源:pool.py

示例10: TF_zoom

# 需要導入模塊: from skimage import transform [as 別名]
# 或者: from skimage.transform import rescale [as 別名]
def TF_zoom(x, scale=1.0, target=None):
    assert len(x.shape) == 3
    h, w, nc = x.shape
    assert h == w

    # Zoom
    xc   = rescale(x, scale)
    diff = h - xc.shape[0]
    d    = int(np.floor(diff / 2.0))
    if d >= 0:
        padding = ((d, d),(d, d),(0,0))
        if diff % 2 != 0:
            padding = ((d,d+1), (d,d + 1),(0,0))
        return np.pad(xc, padding, mode='edge')
    else:
        return xc[-d:h-d, -d:w-d].reshape(h, w, nc) 
開發者ID:HazyResearch,項目名稱:tanda,代碼行數:18,代碼來源:image_tfs.py

示例11: main

# 需要導入模塊: from skimage import transform [as 別名]
# 或者: from skimage.transform import rescale [as 別名]
def main():

  parser = argparse.ArgumentParser(
    formatter_class=argparse.ArgumentDefaultsHelpFormatter)

  parser.add_argument("--image_path",
                      help="path for image to run inference",
                      default="~/demo/data/mscoco_fns/val2014/COCO_val2014_000000301397.jpg")

  args = parser.parse_args()

  args.image_path = os.path.expanduser(args.image_path)

  # Read the image
  image = skimage.io.imread(args.image_path, plugin='imageio')
  image = rescale(image, 2.0, anti_aliasing=False)
  image = img_as_ubyte(image)

  data = json.dumps({"signature_name": "predict", "instances": image.tolist()})
  headers = {"content-type": "application/json"}

  response = requests.post(SERVER_URL, data=data, headers=headers)
  response.raise_for_status()

  predictions = np.squeeze(
    np.array(response.json()["predictions"]), axis=0)
  
  render_image = Image.fromarray(img_as_ubyte(predictions / 255.0), 'RGB')
  plt.imshow(render_image)
  plt.show() 
開發者ID:lambdal,項目名稱:lambda-deep-learning-demo,代碼行數:32,代碼來源:style_transfer_client.py

示例12: draw

# 需要導入模塊: from skimage import transform [as 別名]
# 或者: from skimage.transform import rescale [as 別名]
def draw(self, text, scale=1.0, spacing=0):
        if len(text) == 0:
            return np.zeros((0, 0), dtype=np.uint8)
        try:
            spacing = max(0, spacing)
            image = Image.new('L', tuple(np.add(self.font.getsize(text), [int(self.char_width * spacing * len(text) * 2), 0])), 255)
            draw = ImageDraw.Draw(image)
            if spacing == 0 or len(text.strip()) == 0:
                draw.text((0, 0), text, font=self.font)
                image = np.array(image)[self.offset:, :]

            else:
                x = 0
                for i, c in enumerate(text):
                    draw.text((x, 0), c, font=self.font)
                    w, h = self.font.getsize(c)
                    x += int(spacing * self.char_width + w)
                image = np.array(image)[self.offset:, :]

                sums = np.mean(image, axis=0)
                if np.mean(sums) >= 254:
                    # empty image
                    return np.zeros((0, 0), dtype=np.uint8)

                end = len(sums)
                while sums[end - 1] >= 254:
                    end -= 1
                image = image[:, :end]

            if scale != 1:
                image = rescale(image, float(scale), preserve_range=True)

            return image
        except Exception as e:
            print(e)
            print(text, spacing, scale, len(text.strip()))
            raise e 
開發者ID:Calamari-OCR,項目名稱:calamari,代碼行數:39,代碼來源:line_generator.py

示例13: scale_image

# 需要導入模塊: from skimage import transform [as 別名]
# 或者: from skimage.transform import rescale [as 別名]
def scale_image(image: np.ndarray,
                scaling_y: float,
                scaling_x: float) -> np.ndarray:
    """
    Function to spatially scale an image.

    Parameters
    ----------
    image : numpy.ndarray
        Input image (2D).
    scaling_y : float
        Scaling factor y.
    scaling_x : float
        Scaling factor x.

    Returns
    -------
    numpy.ndarray
        Shifted image (2D).
    """

    sum_before = np.sum(image)

    im_scale = rescale(image=np.asarray(image, dtype=np.float64),
                       scale=(scaling_y, scaling_x),
                       order=5,
                       mode='reflect',
                       anti_aliasing=True,
                       multichannel=False)

    sum_after = np.sum(im_scale)

    return im_scale * (sum_before / sum_after) 
開發者ID:PynPoint,項目名稱:PynPoint,代碼行數:35,代碼來源:image.py

示例14: __call__

# 需要導入模塊: from skimage import transform [as 別名]
# 或者: from skimage.transform import rescale [as 別名]
def __call__(self, img):
        scale_factor = self.max_width / float(img.shape[1])
        if scale_factor <= 1:
            img_small = transform.rescale(img, scale_factor, mode='constant', multichannel=False, anti_aliasing=True)
        else:
            scale_factor = 1.0
            img_small = img
        return img_small, scale_factor 
開發者ID:konstantint,項目名稱:PassportEye,代碼行數:10,代碼來源:image.py

示例15: _try_larger_image

# 需要導入模塊: from skimage import transform [as 別名]
# 或者: from skimage.transform import rescale [as 別名]
def _try_larger_image(self, roi, cur_text, cur_mrz, filter_order=3):
        """Attempts to improve the OCR result by scaling the image. If the new mrz is better, returns it, otherwise returns
        the old mrz."""
        if roi.shape[1] <= 700:
            scale_by = int(1050.0 / roi.shape[1] + 0.5)
            roi_lg = transform.rescale(roi, scale_by, order=filter_order, mode='constant', multichannel=False,
                                       anti_aliasing=True)
            new_text = ocr(roi_lg, extra_cmdline_params=self.extra_cmdline_params)
            new_mrz = MRZ.from_ocr(new_text)
            new_mrz.aux['method'] = 'rescaled(%d)' % filter_order
            if new_mrz.valid_score > cur_mrz.valid_score:
                cur_mrz = new_mrz
                cur_text = new_text
        return cur_text, cur_mrz 
開發者ID:konstantint,項目名稱:PassportEye,代碼行數:16,代碼來源:image.py


注:本文中的skimage.transform.rescale方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。