Stay updated
News & InsightsAPI ReferenceTransforms & TargetsLib ComparisonTargets by TransformFAQLicense Guide
Multi-TargetUltralytics CustomD4 TransformReplayCompose DebugSimple PipelineDomain AdaptationHuggingFace HubText on Imagesexample_xymaskingFace LandmarksSave/Load PipelineKeep All BboxesKeras ClassificationChromatic AberrationTorchvision MigrationMorphologicalMosaic TransformOBB Affine BoatsOverlay ElementsPyTorch ClassificationPyTorch SegmentationRandomGridShuffleKeras SegmentationShowcaseSegmentation (Kaggle)Bounding BoxesKeypointsWeather Transforms
title: "example documents" notebookName: "example_documents.ipynb"
Open in Google ColabRun this notebook interactively
Morphological Transform
import albumentations as A
import cv2
from matplotlib import pyplot as plt
def visualize(image):
plt.figure(figsize=(10, 5))
plt.axis("off")
plt.imshow(image)
Load the image from the disk
img_path = "../images/scan.jpeg"
img = cv2.imread(img_path, cv2.IMREAD_COLOR_RGB)
Visualize the original image
visualize(img)
No code provided
No code providedDilation
Dilation expands the white (foreground) regions in a binary or grayscale image.
transform = A.Compose([A.Morphological(p=1, scale=(2, 3), operation="dilation")], p=1, seed=137, strict=True)
transformed = transform(image=img)
visualize(transformed["image"])
No code provided
No code providedErosion
Erosion shrinks the white (foreground) regions in a binary or grayscale image.
transform = A.Compose([A.Morphological(p=1, scale=(2, 3), operation="erosion")], p=1, seed=137, strict=True)
transformed = transform(image=img)
visualize(transformed["image"])
No code provided
No code provided