本文整理汇总了Python中imgaug.imresize_single_image方法的典型用法代码示例。如果您正苦于以下问题:Python imgaug.imresize_single_image方法的具体用法?Python imgaug.imresize_single_image怎么用?Python imgaug.imresize_single_image使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类imgaug
的用法示例。
在下文中一共展示了imgaug.imresize_single_image方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw_heatmap
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import imresize_single_image [as 别名]
def draw_heatmap(img, heatmap, alpha=0.5):
"""Draw a heatmap overlay over an image."""
assert len(heatmap.shape) == 2 or \
(len(heatmap.shape) == 3 and heatmap.shape[2] == 1)
assert img.dtype in [np.uint8, np.int32, np.int64]
assert heatmap.dtype in [np.float32, np.float64]
if img.shape[0:2] != heatmap.shape[0:2]:
heatmap_rs = np.clip(heatmap * 255, 0, 255).astype(np.uint8)
heatmap_rs = ia.imresize_single_image(
heatmap_rs[..., np.newaxis],
img.shape[0:2],
interpolation="nearest"
)
heatmap = np.squeeze(heatmap_rs) / 255.0
cmap = plt.get_cmap('jet')
heatmap_cmapped = cmap(heatmap)
heatmap_cmapped = np.delete(heatmap_cmapped, 3, 2)
heatmap_cmapped = heatmap_cmapped * 255
mix = (1-alpha) * img + alpha * heatmap_cmapped
mix = np.clip(mix, 0, 255).astype(np.uint8)
return mix
示例2: _perspective_transform_augment_images
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import imresize_single_image [as 别名]
def _perspective_transform_augment_images(self, images, random_state, parents, hooks):
result = images
if not self.keep_size:
result = list(result)
matrices, max_heights, max_widths = self._create_matrices(
[image.shape for image in images],
random_state
)
for i, (M, max_height, max_width) in enumerate(zip(matrices, max_heights, max_widths)):
warped = cv2.warpPerspective(images[i], M, (max_width, max_height))
if warped.ndim == 2 and images[i].ndim == 3:
warped = np.expand_dims(warped, 2)
if self.keep_size:
h, w = images[i].shape[0:2]
warped = ia.imresize_single_image(warped, (h, w))
result[i] = warped
return result
示例3: main
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import imresize_single_image [as 别名]
def main():
augs = [
iaa.Rain(speed=(0.1, 0.3)),
iaa.Rain(),
iaa.Rain(drop_size=(0.1, 0.2))
]
image = imageio.imread(
("https://upload.wikimedia.org/wikipedia/commons/8/89/"
"Kukle%2CCzech_Republic..jpg"),
format="jpg")
for aug, size in zip(augs, [0.1, 0.2, 1.0]):
image_rs = ia.imresize_single_image(image, size, "cubic")
print(image_rs.shape)
images_aug = aug.augment_images([image_rs] * 64)
ia.imshow(ia.draw_grid(images_aug))
示例4: load_images
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import imresize_single_image [as 别名]
def load_images(n_batches=10, sleep=0.0):
batch_size = 4
astronaut = data.astronaut()
astronaut = ia.imresize_single_image(astronaut, (64, 64))
kps = ia.KeypointsOnImage([ia.Keypoint(x=15, y=25)], shape=astronaut.shape)
counter = 0
for i in range(n_batches):
batch_images = []
batch_kps = []
for b in range(batch_size):
astronaut_text = ia.draw_text(astronaut, x=0, y=0, text="%d" % (counter,), color=[0, 255, 0], size=16)
batch_images.append(astronaut_text)
batch_kps.append(kps)
counter += 1
batch = ia.Batch(
images=np.array(batch_images, dtype=np.uint8),
keypoints=batch_kps
)
yield batch
if sleep > 0:
time.sleep(sleep)
示例5: _binarize_mask
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import imresize_single_image [as 别名]
def _binarize_mask(cls, mask, arr_height, arr_width):
# Average over channels, resize to heatmap/segmap array size
# (+clip for cubic interpolation). We can use none-NN interpolation
# for segmaps here as this is just the mask and not the segmap
# array.
mask_3d = np.atleast_3d(mask)
# masks with zero-sized axes crash in np.average() and cannot be
# upscaled in imresize_single_image()
if mask.size == 0:
mask_rs = np.zeros((arr_height, arr_width),
dtype=np.float32)
else:
mask_avg = (
np.average(mask_3d, axis=2) if mask_3d.shape[2] > 0 else 1.0)
mask_rs = ia.imresize_single_image(mask_avg,
(arr_height, arr_width))
mask_arr = iadt.clip_(mask_rs, 0, 1.0)
mask_arr_binarized = (mask_arr >= 0.5)
return mask_arr_binarized
# Added in 0.4.0.
示例6: _augment_images_by_samples
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import imresize_single_image [as 别名]
def _augment_images_by_samples(self, images, samples):
if not self.keep_size:
images = list(images)
kernel_sizes_h, kernel_sizes_w = samples
gen = enumerate(zip(images, kernel_sizes_h, kernel_sizes_w))
for i, (image, ksize_h, ksize_w) in gen:
if ksize_h >= 2 or ksize_w >= 2:
image_pooled = self._pool_image(
image, ksize_h, ksize_w)
if self.keep_size:
image_pooled = ia.imresize_single_image(
image_pooled, image.shape[0:2])
images[i] = image_pooled
return images
# Added in 0.4.0.
示例7: _augment_single_image
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import imresize_single_image [as 别名]
def _augment_single_image(self, image, random_state):
rss = random_state.duplicate(2)
orig_shape = image.shape
image = _ensure_image_max_size(image, self.max_size, self.interpolation)
cell_coordinates = self.points_sampler.sample_points([image], rss[0])[0]
p_replace = self.p_replace.draw_samples((len(cell_coordinates),),
rss[1])
replace_mask = (p_replace > 0.5)
image_aug = segment_voronoi(image, cell_coordinates, replace_mask)
if orig_shape != image_aug.shape:
image_aug = ia.imresize_single_image(
image_aug,
orig_shape[0:2],
interpolation=self.interpolation)
return image_aug
示例8: load_images
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import imresize_single_image [as 别名]
def load_images():
batch_size = 4
astronaut = data.astronaut()
astronaut = ia.imresize_single_image(astronaut, (64, 64))
kps = ia.KeypointsOnImage([ia.Keypoint(x=15, y=25)], shape=astronaut.shape)
counter = 0
for i in range(10):
batch_images = []
batch_kps = []
for b in range(batch_size):
astronaut_text = ia.draw_text(astronaut, x=0, y=0, text="%d" % (counter,), color=[0, 255, 0], size=16)
batch_images.append(astronaut_text)
batch_kps.append(kps)
counter += 1
batch = ia.Batch(
images=np.array(batch_images, dtype=np.uint8),
keypoints=batch_kps
)
yield batch
示例9: set_canvas_background
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import imresize_single_image [as 别名]
def set_canvas_background(self, image):
if self.background_label is None:
# initialize background image label (first call)
#img = self.current_state.screenshot_rs
#bg_img_tk = numpy_to_tk_image(np.zeros(img.shape))
img_heatmap = self._generate_heatmap()
img_heatmap_rs = ia.imresize_single_image(img_heatmap, (img_heatmap.shape[0]*ZOOM_FACTOR, img_heatmap.shape[1]*ZOOM_FACTOR), interpolation="nearest")
bg_img_tk = numpy_to_tk_image(img_heatmap_rs)
self.background_label = Tkinter.Label(self.canvas, image=bg_img_tk)
self.background_label.place(x=0, y=0, relwidth=1, relheight=1, anchor=Tkinter.NW)
self.background_label.image = bg_img_tk
#print("image size", image.shape)
#print("image height, width", image.to_array().shape)
image_rs = ia.imresize_single_image(image, (image.shape[0]*ZOOM_FACTOR, image.shape[1]*ZOOM_FACTOR), interpolation="nearest")
image_tk = numpy_to_tk_image(image_rs)
self.background_label.configure(image=image_tk)
self.background_label.image = image_tk
示例10: set_canvas_background
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import imresize_single_image [as 别名]
def set_canvas_background(self, image):
if self.background_label is None:
# initialize background image label (first call)
#img = self.current_state.screenshot_rs
#bg_img_tk = numpy_to_tk_image(np.zeros(img.shape))
img_heatmap = self._generate_heatmap()
img_heatmap_rs = ia.imresize_single_image(img_heatmap, (img_heatmap.shape[0]*self.zoom_factor, img_heatmap.shape[1]*self.zoom_factor), interpolation="nearest")
bg_img_tk = numpy_to_tk_image(img_heatmap_rs)
self.background_label = Tkinter.Label(self.canvas, image=bg_img_tk)
self.background_label.place(x=0, y=0, relwidth=1, relheight=1, anchor=Tkinter.NW)
self.background_label.image = bg_img_tk
#print("image size", image.shape)
#print("image height, width", image.to_array().shape)
image_rs = ia.imresize_single_image(image, (image.shape[0]*self.zoom_factor, image.shape[1]*self.zoom_factor), interpolation="nearest")
image_tk = numpy_to_tk_image(image_rs)
self.background_label.configure(image=image_tk)
self.background_label.image = image_tk
示例11: draw_heatmap_overlay
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import imresize_single_image [as 别名]
def draw_heatmap_overlay(img, heatmap, alpha=0.5):
#assert img.shape[0:2] == heatmap.shape[0:2]
assert len(heatmap.shape) == 2 or (heatmap.ndim == 3 and heatmap.shape[2] == 1)
assert img.dtype in [np.uint8, np.int32, np.int64]
assert heatmap.dtype in [np.float32, np.float64]
if heatmap.ndim == 3 and heatmap.shape[2] == 1:
heatmap = np.squeeze(heatmap)
if img.shape[0:2] != heatmap.shape[0:2]:
heatmap_rs = np.clip(heatmap * 255, 0, 255).astype(np.uint8)
heatmap_rs = ia.imresize_single_image(heatmap_rs[..., np.newaxis], img.shape[0:2], interpolation="nearest")
heatmap = np.squeeze(heatmap_rs) / 255.0
cmap = plt.get_cmap('jet')
heatmap_cmapped = cmap(heatmap)
#img_heatmaps_cmapped = img_heatmaps_cmapped[:, :, 0:3]
heatmap_cmapped = np.delete(heatmap_cmapped, 3, 2)
#heatmap_cmapped = np.clip(heatmap_cmapped * 255, 0, 255).astype(np.uint8)
heatmap_cmapped = heatmap_cmapped * 255
mix = (1-alpha) * img + alpha * heatmap_cmapped
mix = np.clip(mix, 0, 255).astype(np.uint8)
return mix
示例12: imresize_sidelen
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import imresize_single_image [as 别名]
def imresize_sidelen(image, maxval, pick_func=min, interpolation=None, force_even_sidelens=False):
"""Resize an image so that one of its size is not larger than a maximum
value."""
height, width = image.shape[0], image.shape[1]
currval = pick_func(height, width)
if currval < maxval:
if force_even_sidelens:
newheight = height
newwidth = width
if newheight % 2 != 0:
newheight += 1
if newwidth % 2 != 0:
newwidth += 1
if newheight == height and newwidth == width:
return np.copy(image)
else:
return ia.imresize_single_image(
image,
(newheight, newwidth),
interpolation=interpolation
)
else:
return np.copy(image)
else:
scale_factor = maxval / currval
newheight, newwidth = int(height * scale_factor), int(width * scale_factor)
if force_even_sidelens:
if newheight % 2 != 0:
newheight += 1
if newwidth % 2 != 0:
newwidth += 1
return ia.imresize_single_image(
image,
(newheight, newwidth),
interpolation=interpolation
)
示例13: find_bbs
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import imresize_single_image [as 别名]
def find_bbs(img, model, conf_threshold, input_size):
"""Find bounding boxes in an image."""
# pad image so that its square
img_pad, (pad_top, pad_right, pad_bottom, pad_left) = to_aspect_ratio_add(img, 1.0, return_paddings=True)
# resize padded image to desired input size
# "linear" interpolation seems to be enough here for 400x400 or larger images
# change to "area" or "cubic" for marginally better quality
img_rs = ia.imresize_single_image(img_pad, (input_size, input_size), interpolation="linear")
# convert to torch-ready input variable
inputs_np = (np.array([img_rs])/255.0).astype(np.float32).transpose(0, 3, 1, 2)
inputs = torch.from_numpy(inputs_np)
inputs = Variable(inputs, volatile=True)
if GPU >= 0:
inputs = inputs.cuda(GPU)
# apply model and measure the model's time
time_start = time.time()
outputs_pred = model(inputs)
time_req = time.time() - time_start
# process the model's output (i.e. convert heatmaps to BBs)
result = ModelResult(
outputs_pred,
inputs_np,
img,
(pad_top, pad_right, pad_bottom, pad_left)
)
bbs = result.get_bbs()
return bbs, time_req
示例14: main
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import imresize_single_image [as 别名]
def main():
image = data.astronaut()
image = ia.imresize_single_image(image, (HEIGHT, WIDTH))
kps = []
for y in range(NB_ROWS):
ycoord = BB_Y1 + int(y * (BB_Y2 - BB_Y1) / (NB_COLS - 1))
for x in range(NB_COLS):
xcoord = BB_X1 + int(x * (BB_X2 - BB_X1) / (NB_ROWS - 1))
kp = (xcoord, ycoord)
kps.append(kp)
kps = set(kps)
kps = [ia.Keypoint(x=xcoord, y=ycoord) for (xcoord, ycoord) in kps]
kps = ia.KeypointsOnImage(kps, shape=image.shape)
bb = ia.BoundingBox(x1=BB_X1, x2=BB_X2, y1=BB_Y1, y2=BB_Y2)
bbs = ia.BoundingBoxesOnImage([bb], shape=image.shape)
seq = iaa.Affine(rotate=45)
seq_det = seq.to_deterministic()
image_aug = seq_det.augment_image(image)
kps_aug = seq_det.augment_keypoints([kps])[0]
bbs_aug = seq_det.augment_bounding_boxes([bbs])[0]
image_before = np.copy(image)
image_before = kps.draw_on_image(image_before)
image_before = bbs.draw_on_image(image_before)
image_after = np.copy(image_aug)
image_after = kps_aug.draw_on_image(image_after)
image_after = bbs_aug.draw_on_image(image_after)
ia.imshow(np.hstack([image_before, image_after]))
imageio.imwrite("bb_aug.jpg", np.hstack([image_before, image_after]))
示例15: main
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import imresize_single_image [as 别名]
def main():
for size in [0.1, 0.2, 1.0]:
image = imageio.imread("https://upload.wikimedia.org/wikipedia/commons/8/89/Kukle%2CCzech_Republic..jpg",
format="jpg")
image = ia.imresize_single_image(image, size, "cubic")
print(image.shape)
augs = [
("iaa.Fog()", iaa.Fog())
]
for descr, aug in augs:
print(descr)
images_aug = aug.augment_images([image] * 64)
ia.imshow(ia.draw_grid(images_aug))