1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| def display_augmentations(path): original = cv2.imread(path) original = cv2.cvtColor(original, cv2.COLOR_BGR2RGB)
transform_rgb = alb.Compose([RGBShift(g_shift_limit=50, always_apply=True)])
transform_hsv = alb.Compose([HueSaturationValue(hue_shift_limit=10,\ sat_shift_limit=60, always_apply=True)])
transform_hf = alb.Compose([HorizontalFlip(always_apply=True)]) transform_clahe = alb.Compose([CLAHE(clip_limit=10.0, always_apply=True)]) transform_rc = alb.Compose([RandomCrop(height=300, width=300, always_apply=True)]) transform_rg = alb.Compose([RandomGamma(gamma_limit=(200, 400), always_apply=True)]) transform_rot = alb.Compose([Rotate(limit=90, always_apply=True)]) transform_cc = alb.Compose([CenterCrop(height=450, width=450, always_apply=True)]) transform_mb = alb.Compose([MedianBlur(blur_limit=103, always_apply=True)]) transform_vf = alb.Compose([VerticalFlip(always_apply=True)]) transform_ii = alb.Compose([InvertImg(always_apply=True)])
transformed_rgb = transform_rgb(image=original)['image'] transformed_hsv = transform_hsv(image=original)["image"] transformed_hf = transform_hf(image=original)["image"] transformed_clahe = transform_clahe(image=original)["image"] transformed_rc = transform_rc(image=original)["image"] transformed_rg = transform_rg(image=original)["image"] transformed_rot = transform_rot(image=original)["image"] transformed_cc = transform_cc(image=original)["image"] transformed_mb = transform_mb(image=original)["image"] transformed_vf = transform_vf(image=original)["image"] transformed_ii = transform_ii(image=original)["image"]
all_transformations = [original, transformed_rgb, transformed_hsv, transformed_hf, transformed_clahe, transformed_rc, transformed_rg, transformed_rot, transformed_cc, transformed_mb, transformed_vf, transformed_ii] all_names = ["Original", "RGBShift", "HueStaurationValue", "HorizontalFlip", "CLAHE", "RandomCrop", "RandomGamma", "Rotate", "CenterCrop", "MedianBlur", "VerticalFlip", "InvertImg"]
fig = plt.figure(figsize=(28, 20)) plt.suptitle(f"Image Augmentations", fontsize=20) for k, image in enumerate(all_transformations): fig.add_subplot(3, 4, k+1) plt.title(all_names[k]) plt.imshow(image) plt.axis("off") plt.show() example_path = r"hellokity.jpg" display_augmentations(path=example_path)
|