Python skimage.data.astronaut() Examples
The following are 27
code examples of skimage.data.astronaut().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
skimage.data
, or try the search function
.
Example #1
Source File: check_add_to_hue_and_saturation.py From imgaug with MIT License | 6 votes |
def main(): image = data.astronaut() cv2.namedWindow("aug", cv2.WINDOW_NORMAL) cv2.imshow("aug", image) cv2.waitKey(TIME_PER_STEP) # for value in cycle(np.arange(-255, 255, VAL_PER_STEP)): for value in np.arange(-255, 255, VAL_PER_STEP): aug = iaa.AddToHueAndSaturation(value=value) img_aug = aug.augment_image(image) img_aug = iaa.pad(img_aug, bottom=40) img_aug = ia.draw_text(img_aug, x=0, y=img_aug.shape[0]-38, text="value=%d" % (value,), size=30) cv2.imshow("aug", img_aug) cv2.waitKey(TIME_PER_STEP) images_aug = iaa.AddToHueAndSaturation(value=(-255, 255), per_channel=True).augment_images([image] * 64) ia.imshow(ia.draw_grid(images_aug)) image = ia.quokka_square((128, 128)) images_aug = [] images_aug.extend(iaa.AddToHue().augment_images([image] * 10)) images_aug.extend(iaa.AddToSaturation().augment_images([image] * 10)) ia.imshow(ia.draw_grid(images_aug, rows=2))
Example #2
Source File: check_color.py From DL.EyeSight with GNU General Public License v3.0 | 6 votes |
def main_WithColorspace(): image = data.astronaut() print("image shape:", image.shape) aug = WithColorspace( from_colorspace="RGB", to_colorspace="HSV", children=WithChannels(0, Add(50)) ) aug_no_colorspace = WithChannels(0, Add(50)) img_show = np.hstack([ image, aug.augment_image(image), aug_no_colorspace.augment_image(image) ]) cv2.namedWindow("aug", cv2.WINDOW_NORMAL) cv2.imshow("aug", img_show[..., ::-1]) cv2.waitKey(TIME_PER_STEP)
Example #3
Source File: check_background_augmentation.py From ViolenceDetection with Apache License 2.0 | 6 votes |
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
Example #4
Source File: check_background.py From DL.EyeSight with GNU General Public License v3.0 | 6 votes |
def load_images(): batch_size = 4 astronaut = data.astronaut() astronaut = eu.imresize_single_image(astronaut, (64, 64)) kps = KeyPointsOnImage([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): batch_images.append(astronaut) batch_kps.append(kps) counter += 1 batch = Batch( images=np.array(batch_images, dtype=np.uint8), keypoints=batch_kps ) yield batch
Example #5
Source File: check_directed_edge_detect.py From imgaug with MIT License | 6 votes |
def main(): image = data.astronaut() cv2.namedWindow("aug", cv2.WINDOW_NORMAL) cv2.imshow("aug", image) cv2.waitKey(TIME_PER_STEP) height, width = image.shape[0], image.shape[1] center_x = width // 2 center_y = height // 2 r = int(min(image.shape[0], image.shape[1]) / 3) for deg in cycle(np.arange(0, 360, DEG_PER_STEP)): rad = np.deg2rad(deg-90) point_x = int(center_x + r * np.cos(rad)) point_y = int(center_y + r * np.sin(rad)) direction = deg / 360 aug = iaa.DirectedEdgeDetect(alpha=1.0, direction=direction) img_aug = aug.augment_image(image) img_aug[point_y-POINT_SIZE:point_y+POINT_SIZE+1, point_x-POINT_SIZE:point_x+POINT_SIZE+1, :] =\ np.array([0, 255, 0]) cv2.imshow("aug", img_aug) cv2.waitKey(TIME_PER_STEP)
Example #6
Source File: check_seed.py From imgaug with MIT License | 6 votes |
def main(): img = data.astronaut() img = ia.imresize_single_image(img, (64, 64)) aug = iaa.Fliplr(0.5) unseeded1 = aug.draw_grid(img, cols=8, rows=1) unseeded2 = aug.draw_grid(img, cols=8, rows=1) iarandom.seed(1000) seeded1 = aug.draw_grid(img, cols=8, rows=1) seeded2 = aug.draw_grid(img, cols=8, rows=1) iarandom.seed(1000) reseeded1 = aug.draw_grid(img, cols=8, rows=1) reseeded2 = aug.draw_grid(img, cols=8, rows=1) iarandom.seed(1001) reseeded3 = aug.draw_grid(img, cols=8, rows=1) reseeded4 = aug.draw_grid(img, cols=8, rows=1) all_rows = np.vstack([unseeded1, unseeded2, seeded1, seeded2, reseeded1, reseeded2, reseeded3, reseeded4]) ia.imshow(all_rows)
Example #7
Source File: check_superpixels.py From ViolenceDetection with Apache License 2.0 | 6 votes |
def main(): image = data.astronaut()[...,::-1] # rgb2bgr print(image.shape) cv2.namedWindow("aug", cv2.WINDOW_NORMAL) cv2.imshow("aug", image) cv2.waitKey(TIME_PER_STEP) for n_segments in cycle(reversed(np.arange(1, 200, SEGMENTS_PER_STEP))): aug = iaa.Superpixels(p_replace=0.75, n_segments=n_segments) time_start = time.time() img_aug = aug.augment_image(image) print("augmented %d in %.4fs" % (n_segments, time.time() - time_start)) img_aug = ia.draw_text(img_aug, x=5, y=5, text="%d" % (n_segments,)) cv2.imshow("aug", img_aug) cv2.waitKey(TIME_PER_STEP)
Example #8
Source File: check_superpixels.py From imgaug with MIT License | 6 votes |
def main(): image = data.astronaut()[..., ::-1] # rgb2bgr print(image.shape) cv2.namedWindow("aug", cv2.WINDOW_NORMAL) cv2.imshow("aug", image) cv2.waitKey(TIME_PER_STEP) for n_segments in cycle(reversed(np.arange(1, 200, SEGMENTS_PER_STEP))): aug = iaa.Superpixels(p_replace=0.75, n_segments=n_segments) time_start = time.time() img_aug = aug.augment_image(image) print("augmented %d in %.4fs" % (n_segments, time.time() - time_start)) img_aug = ia.draw_text(img_aug, x=5, y=5, text="%d" % (n_segments,)) cv2.imshow("aug", img_aug) cv2.waitKey(TIME_PER_STEP)
Example #9
Source File: check_seed.py From ViolenceDetection with Apache License 2.0 | 6 votes |
def main(): img = data.astronaut() img = misc.imresize(img, (64, 64)) aug = iaa.Fliplr(0.5) unseeded1 = aug.draw_grid(img, cols=8, rows=1) unseeded2 = aug.draw_grid(img, cols=8, rows=1) ia.seed(1000) seeded1 = aug.draw_grid(img, cols=8, rows=1) seeded2 = aug.draw_grid(img, cols=8, rows=1) ia.seed(1000) reseeded1 = aug.draw_grid(img, cols=8, rows=1) reseeded2 = aug.draw_grid(img, cols=8, rows=1) ia.seed(1001) reseeded3 = aug.draw_grid(img, cols=8, rows=1) reseeded4 = aug.draw_grid(img, cols=8, rows=1) all_rows = np.vstack([unseeded1, unseeded2, seeded1, seeded2, reseeded1, reseeded2, reseeded3, reseeded4]) misc.imshow(all_rows)
Example #10
Source File: check_withcolorspace.py From ViolenceDetection with Apache License 2.0 | 6 votes |
def main(): image = data.astronaut() print("image shape:", image.shape) aug = iaa.WithColorspace( from_colorspace="RGB", to_colorspace="HSV", children=iaa.WithChannels(0, iaa.Add(50)) ) aug_no_colorspace = iaa.WithChannels(0, iaa.Add(50)) img_show = np.hstack([ image, aug.augment_image(image), aug_no_colorspace.augment_image(image) ]) misc.imshow(img_show)
Example #11
Source File: check_background_augmentation.py From imgaug with MIT License | 6 votes |
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)
Example #12
Source File: bm_comp_perform.py From BIRL with BSD 3-Clause "New" or "Revised" License | 6 votes |
def _prepare_images(path_out, im_size=IMAGE_SIZE): """ generate and prepare synth. images for registration :param str path_out: path to the folder :param tuple(int,int) im_size: desired image size :return tuple(str,str): paths to target and source image """ image = resize(data.astronaut(), output_shape=im_size, mode='constant') img_target = random_noise(image, var=IMAGE_NOISE) path_img_target = os.path.join(path_out, NAME_IMAGE_TARGET) io.imsave(path_img_target, img_target) # warp synthetic image tform = AffineTransform(scale=(0.9, 0.9), rotation=0.2, translation=(200, -50)) img_source = warp(image, tform.inverse, output_shape=im_size) img_source = random_noise(img_source, var=IMAGE_NOISE) path_img_source = os.path.join(path_out, NAME_IMAGE_SOURCE) io.imsave(path_img_source, img_source) return path_img_target, path_img_source
Example #13
Source File: check_median_blur.py From ViolenceDetection with Apache License 2.0 | 5 votes |
def main(): image = data.astronaut() image = ia.imresize_single_image(image, (64, 64)) print("image shape:", image.shape) print("Press any key or wait %d ms to proceed to the next image." % (TIME_PER_STEP,)) k = [ 1, 3, 5, 7, (3, 3), (1, 11) ] cv2.namedWindow("aug", cv2.WINDOW_NORMAL) cv2.resizeWindow("aug", 64*NB_AUGS_PER_IMAGE, 64) #cv2.imshow("aug", image[..., ::-1]) #cv2.waitKey(TIME_PER_STEP) for ki in k: aug = iaa.MedianBlur(k=ki) img_aug = [aug.augment_image(image) for _ in range(NB_AUGS_PER_IMAGE)] img_aug = np.hstack(img_aug) print("dtype", img_aug.dtype, "averages", np.average(img_aug, axis=tuple(range(0, img_aug.ndim-1)))) #print("dtype", img_aug.dtype, "averages", img_aug.mean(axis=range(1, img_aug.ndim))) title = "k=%s" % (str(ki),) img_aug = ia.draw_text(img_aug, x=5, y=5, text=title) cv2.imshow("aug", img_aug[..., ::-1]) # here with rgb2bgr cv2.waitKey(TIME_PER_STEP)
Example #14
Source File: check_average_blur.py From ViolenceDetection with Apache License 2.0 | 5 votes |
def main(): image = data.astronaut() image = ia.imresize_single_image(image, (64, 64)) print("image shape:", image.shape) print("Press any key or wait %d ms to proceed to the next image." % (TIME_PER_STEP,)) k = [ 1, 2, 4, 8, 16, (8, 8), (1, 8), ((1, 1), (8, 8)), ((1, 16), (1, 16)), ((1, 16), 1) ] cv2.namedWindow("aug", cv2.WINDOW_NORMAL) cv2.resizeWindow("aug", 64*NB_AUGS_PER_IMAGE, 64) #cv2.imshow("aug", image[..., ::-1]) #cv2.waitKey(TIME_PER_STEP) for ki in k: aug = iaa.AverageBlur(k=ki) img_aug = [aug.augment_image(image) for _ in range(NB_AUGS_PER_IMAGE)] img_aug = np.hstack(img_aug) print("dtype", img_aug.dtype, "averages", np.average(img_aug, axis=tuple(range(0, img_aug.ndim-1)))) #print("dtype", img_aug.dtype, "averages", img_aug.mean(axis=range(1, img_aug.ndim))) title = "k=%s" % (str(ki),) img_aug = ia.draw_text(img_aug, x=5, y=5, text=title) cv2.imshow("aug", img_aug[..., ::-1]) # here with rgb2bgr cv2.waitKey(TIME_PER_STEP)
Example #15
Source File: check_withchannels.py From ViolenceDetection with Apache License 2.0 | 5 votes |
def main(): image = data.astronaut() print("image shape:", image.shape) print("Press any key or wait %d ms to proceed to the next image." % (TIME_PER_STEP,)) children_all = [ ("hflip", iaa.Fliplr(1)), ("add", iaa.Add(50)), ("dropout", iaa.Dropout(0.2)), ("affine", iaa.Affine(rotate=35)) ] channels_all = [ None, 0, [], [0], [0, 1], [1, 2], [0, 1, 2] ] cv2.namedWindow("aug", cv2.WINDOW_NORMAL) cv2.imshow("aug", image[..., ::-1]) cv2.waitKey(TIME_PER_STEP) for children_title, children in children_all: for channels in channels_all: aug = iaa.WithChannels(channels=channels, children=children) img_aug = aug.augment_image(image) print("dtype", img_aug.dtype, "averages", np.average(img_aug, axis=tuple(range(0, img_aug.ndim-1)))) #print("dtype", img_aug.dtype, "averages", img_aug.mean(axis=range(1, img_aug.ndim))) title = "children=%s | channels=%s" % (children_title, channels) img_aug = ia.draw_text(img_aug, x=5, y=5, text=title) cv2.imshow("aug", img_aug[..., ::-1]) # here with rgb2bgr cv2.waitKey(TIME_PER_STEP)
Example #16
Source File: check_directed_edge_detect.py From ViolenceDetection with Apache License 2.0 | 5 votes |
def main(): image = data.astronaut() cv2.namedWindow("aug", cv2.WINDOW_NORMAL) cv2.imshow("aug", image) cv2.waitKey(TIME_PER_STEP) height, width = image.shape[0], image.shape[1] center_x = width // 2 center_y = height // 2 r = int(min(image.shape[0], image.shape[1]) / 3) for deg in cycle(np.arange(0, 360, DEG_PER_STEP)): rad = np.deg2rad(deg-90) #print(deg, rad) point_x = int(center_x + r * np.cos(rad)) point_y = int(center_y + r * np.sin(rad)) direction = deg / 360 aug = iaa.DirectedEdgeDetect(alpha=1.0, direction=direction) img_aug = aug.augment_image(image) img_aug[point_y-POINT_SIZE:point_y+POINT_SIZE+1, point_x-POINT_SIZE:point_x+POINT_SIZE+1, :] = np.array([0, 255, 0]) #print(point_x, point_y) cv2.imshow("aug", img_aug) cv2.waitKey(TIME_PER_STEP)
Example #17
Source File: check_bb_augmentation.py From ViolenceDetection with Apache License 2.0 | 5 votes |
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) misc.imshow(np.hstack([image_before, image_after])) misc.imsave("bb_aug.jpg", np.hstack([image_before, image_after]))
Example #18
Source File: check_average_blur.py From DL.EyeSight with GNU General Public License v3.0 | 5 votes |
def main(): image = data.astronaut() image = eu.imresize_single_image(image, (64, 64)) print("image shape:", image.shape) print("Press any key or wait %d ms to proceed to the next image." % (TIME_PER_STEP,)) k = [ 1, 2, 4, 8, 16, (8, 8), (1, 8), ((1, 1), (8, 8)), ((1, 16), (1, 16)), ((1, 16), 1) ] cv2.namedWindow("aug", cv2.WINDOW_NORMAL) cv2.resizeWindow("aug", 64*NB_AUGS_PER_IMAGE, 64) #cv2.imshow("aug", image[..., ::-1]) #cv2.waitKey(TIME_PER_STEP) for ki in k: aug = AverageBlur(k=ki) img_aug = [aug.augment_image(image) for _ in range(NB_AUGS_PER_IMAGE)] img_aug = np.hstack(img_aug) print("dtype", img_aug.dtype, "averages", np.average(img_aug, axis=tuple(range(0, img_aug.ndim-1)))) #print("dtype", img_aug.dtype, "averages", img_aug.mean(axis=range(1, img_aug.ndim))) # title = "k=%s" % (str(ki),) # img_aug = ia.draw_text(img_aug, x=5, y=5, text=title) cv2.imshow("aug", img_aug[..., ::-1]) # here with rgb2bgr cv2.waitKey(TIME_PER_STEP)
Example #19
Source File: check_color.py From DL.EyeSight with GNU General Public License v3.0 | 5 votes |
def main_WithChannels(): image = data.astronaut() print("image shape:", image.shape) print("Press any key or wait %d ms to proceed to the next image." % (TIME_PER_STEP,)) children_all = [ ("hflip", Fliplr(1)), ("add", Add(50)) ] channels_all = [ None, 0, [], [0], [0, 1], [1, 2], [0, 1, 2] ] cv2.namedWindow("aug", cv2.WINDOW_NORMAL) cv2.imshow("aug", image[..., ::-1]) cv2.waitKey(TIME_PER_STEP) for children_title, children in children_all: for channels in channels_all: aug = WithChannels(channels=channels, children=children) img_aug = aug.augment_image(image) print("dtype", img_aug.dtype, "averages", np.average(img_aug, axis=tuple(range(0, img_aug.ndim-1)))) #print("dtype", img_aug.dtype, "averages", img_aug.mean(axis=range(1, img_aug.ndim))) # title = "children=%s | channels=%s" % (children_title, channels) # img_aug = ia.draw_text(img_aug, x=5, y=5, text=title) cv2.imshow("aug", img_aug[..., ::-1]) # here with rgb2bgr cv2.waitKey(TIME_PER_STEP)
Example #20
Source File: check_gaussian_blur.py From DL.EyeSight with GNU General Public License v3.0 | 5 votes |
def main(): image = data.astronaut() image = eu.imresize_single_image(image, (128, 128)) print("image shape:", image.shape) print("Press any key or wait %d ms to proceed to the next image." % (TIME_PER_STEP,)) k = [ 1, 3, 5, 7, (3, 3), (1, 11) ] cv2.namedWindow("aug", cv2.WINDOW_NORMAL) cv2.resizeWindow("aug", 128*NB_AUGS_PER_IMAGE, 128) #cv2.imshow("aug", image[..., ::-1]) #cv2.waitKey(TIME_PER_STEP) for ki in k: aug = MedianBlur(k=ki) img_aug = [aug.augment_image(image) for _ in range(NB_AUGS_PER_IMAGE)] img_aug = np.hstack(img_aug) print("dtype", img_aug.dtype, "averages", np.average(img_aug, axis=tuple(range(0, img_aug.ndim-1)))) #print("dtype", img_aug.dtype, "averages", img_aug.mean(axis=range(1, img_aug.ndim))) # title = "k=%s" % (str(ki),) # img_aug = ia.draw_text(img_aug, x=5, y=5, text=title) cv2.imshow("aug", img_aug[..., ::-1]) # here with rgb2bgr cv2.waitKey(TIME_PER_STEP)
Example #21
Source File: check_median_blur.py From imgaug with MIT License | 5 votes |
def main(): image = data.astronaut() image = ia.imresize_single_image(image, (64, 64)) print("image shape:", image.shape) print("Press any key or wait %d ms to proceed to the next image." % (TIME_PER_STEP,)) k = [ 1, 3, 5, 7, (3, 3), (1, 11) ] cv2.namedWindow("aug", cv2.WINDOW_NORMAL) cv2.resizeWindow("aug", 64*NB_AUGS_PER_IMAGE, 64) for ki in k: aug = iaa.MedianBlur(k=ki) img_aug = [aug.augment_image(image) for _ in range(NB_AUGS_PER_IMAGE)] img_aug = np.hstack(img_aug) print("dtype", img_aug.dtype, "averages", np.average(img_aug, axis=tuple(range(0, img_aug.ndim-1)))) title = "k=%s" % (str(ki),) img_aug = ia.draw_text(img_aug, x=5, y=5, text=title) cv2.imshow("aug", img_aug[..., ::-1]) # here with rgb2bgr cv2.waitKey(TIME_PER_STEP)
Example #22
Source File: check_multicore_pool.py From imgaug with MIT License | 5 votes |
def load_images(n_batches=10, sleep=0.0, draw_text=True): 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): if draw_text: 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 ) else: if i == 0: batch_images = np.array([np.copy(astronaut) for _ in range(batch_size)], dtype=np.uint8) batch = ia.Batch( images=np.copy(batch_images), keypoints=[kps.deepcopy() for _ in range(batch_size)] ) yield batch if sleep > 0: time.sleep(sleep)
Example #23
Source File: check_bilateral_blur.py From imgaug with MIT License | 5 votes |
def main(): image = data.astronaut() image = ia.imresize_single_image(image, (128, 128)) print("image shape:", image.shape) print("Press any key or wait %d ms to proceed to the next image." % (TIME_PER_STEP,)) configs = [ (1, 75, 75), (3, 75, 75), (5, 75, 75), (10, 75, 75), (10, 25, 25), (10, 250, 150), (15, 75, 75), (15, 150, 150), (15, 250, 150), (20, 75, 75), (40, 150, 150), ((1, 5), 75, 75), (5, (10, 250), 75), (5, 75, (10, 250)), (5, (10, 250), (10, 250)), (10, (10, 250), (10, 250)), ] cv2.namedWindow("aug", cv2.WINDOW_NORMAL) cv2.resizeWindow("aug", 128*NB_AUGS_PER_IMAGE, 128) for (d, sigma_color, sigma_space) in configs: aug = iaa.BilateralBlur(d=d, sigma_color=sigma_color, sigma_space=sigma_space) img_aug = [aug.augment_image(image) for _ in range(NB_AUGS_PER_IMAGE)] img_aug = np.hstack(img_aug) print("dtype", img_aug.dtype, "averages", np.average(img_aug, axis=tuple(range(0, img_aug.ndim-1)))) title = "d=%s, sc=%s, ss=%s" % (str(d), str(sigma_color), str(sigma_space)) img_aug = ia.draw_text(img_aug, x=5, y=5, text=title) cv2.imshow("aug", img_aug[..., ::-1]) # here with rgb2bgr cv2.waitKey(TIME_PER_STEP)
Example #24
Source File: check_average_blur.py From imgaug with MIT License | 5 votes |
def main(): image = data.astronaut() image = ia.imresize_single_image(image, (64, 64)) print("image shape:", image.shape) print("Press any key or wait %d ms to proceed to the next image." % (TIME_PER_STEP,)) k = [ 1, 2, 4, 8, 16, (8, 8), (1, 8), ((1, 1), (8, 8)), ((1, 16), (1, 16)), ((1, 16), 1) ] cv2.namedWindow("aug", cv2.WINDOW_NORMAL) cv2.resizeWindow("aug", 64*NB_AUGS_PER_IMAGE, 64) for ki in k: aug = iaa.AverageBlur(k=ki) img_aug = [aug.augment_image(image) for _ in range(NB_AUGS_PER_IMAGE)] img_aug = np.hstack(img_aug) print("dtype", img_aug.dtype, "averages", np.average(img_aug, axis=tuple(range(0, img_aug.ndim-1)))) title = "k=%s" % (str(ki),) img_aug = ia.draw_text(img_aug, x=5, y=5, text=title) cv2.imshow("aug", img_aug[..., ::-1]) # here with rgb2bgr cv2.waitKey(TIME_PER_STEP)
Example #25
Source File: check_withchannels.py From imgaug with MIT License | 5 votes |
def main(): image = data.astronaut() print("image shape:", image.shape) print("Press ENTER or wait %d ms to proceed to the next image." % (TIME_PER_STEP,)) children_all = [ ("hflip", iaa.Fliplr(1)), ("add", iaa.Add(50)), ("dropout", iaa.Dropout(0.2)), ("affine", iaa.Affine(rotate=35)) ] channels_all = [ None, 0, [], [0], [0, 1], [1, 2], [0, 1, 2] ] cv2.namedWindow("aug", cv2.WINDOW_NORMAL) cv2.imshow("aug", image[..., ::-1]) cv2.waitKey(TIME_PER_STEP) for children_title, children in children_all: for channels in channels_all: aug = iaa.WithChannels(channels=channels, children=children) img_aug = aug.augment_image(image) print("dtype", img_aug.dtype, "averages", np.average(img_aug, axis=tuple(range(0, img_aug.ndim-1)))) title = "children=%s | channels=%s" % (children_title, channels) img_aug = ia.draw_text(img_aug, x=5, y=5, text=title) cv2.imshow("aug", img_aug[..., ::-1]) # here with rgb2bgr cv2.waitKey(TIME_PER_STEP)
Example #26
Source File: check_bb_augmentation.py From imgaug with MIT License | 5 votes |
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]))
Example #27
Source File: check_elastic_transformation.py From ViolenceDetection with Apache License 2.0 | 4 votes |
def main(): image = data.astronaut() image = ia.imresize_single_image(image, (128, 128)) images = [] params = [ (0.25, 0.25), (1.0, 0.25), (2.0, 0.25), (3.0, 0.25), (0.25, 0.50), (1.0, 0.50), (2.0, 0.50), (3.0, 0.50), (0.25, 0.75), (1.0, 0.75), (2.0, 0.75), (3.0, 0.75) ] for (alpha, sigma) in params: images_row = [] seqs_row = [ iaa.ElasticTransformation(alpha=alpha, sigma=sigma, mode="constant", cval=0, order=0), iaa.ElasticTransformation(alpha=alpha, sigma=sigma, mode="constant", cval=128, order=0), iaa.ElasticTransformation(alpha=alpha, sigma=sigma, mode="constant", cval=255, order=0), iaa.ElasticTransformation(alpha=alpha, sigma=sigma, mode="constant", cval=0, order=1), iaa.ElasticTransformation(alpha=alpha, sigma=sigma, mode="constant", cval=128, order=1), iaa.ElasticTransformation(alpha=alpha, sigma=sigma, mode="constant", cval=255, order=1), iaa.ElasticTransformation(alpha=alpha, sigma=sigma, mode="constant", cval=0, order=3), iaa.ElasticTransformation(alpha=alpha, sigma=sigma, mode="constant", cval=128, order=3), iaa.ElasticTransformation(alpha=alpha, sigma=sigma, mode="constant", cval=255, order=3), iaa.ElasticTransformation(alpha=alpha, sigma=sigma, mode="nearest", order=0), iaa.ElasticTransformation(alpha=alpha, sigma=sigma, mode="nearest", order=1), iaa.ElasticTransformation(alpha=alpha, sigma=sigma, mode="nearest", order=2), iaa.ElasticTransformation(alpha=alpha, sigma=sigma, mode="nearest", order=3), iaa.ElasticTransformation(alpha=alpha, sigma=sigma, mode="reflect", order=0), iaa.ElasticTransformation(alpha=alpha, sigma=sigma, mode="reflect", order=1), iaa.ElasticTransformation(alpha=alpha, sigma=sigma, mode="reflect", order=2), iaa.ElasticTransformation(alpha=alpha, sigma=sigma, mode="reflect", order=3), iaa.ElasticTransformation(alpha=alpha, sigma=sigma, mode="wrap", order=0), iaa.ElasticTransformation(alpha=alpha, sigma=sigma, mode="wrap", order=1), iaa.ElasticTransformation(alpha=alpha, sigma=sigma, mode="wrap", order=2), iaa.ElasticTransformation(alpha=alpha, sigma=sigma, mode="wrap", order=3) ] for seq in seqs_row: images_row.append( seq.augment_image(image) ) images.append(np.hstack(images_row)) misc.imshow(np.vstack(images)) misc.imsave("elastic_transformations.jpg", np.vstack(images))