本文整理汇总了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
示例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])
示例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
# -----------------------------------------------------------------------------
示例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)
示例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))
示例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))
示例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))
示例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())
示例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)
示例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)
示例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()
示例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
示例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)
示例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
示例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