Auto Rotate on Edges¶
Class: AutoRotateOnEdgesBlockV1
Source: inference.core.workflows.core_steps.classical_cv.auto_rotate_on_edges.v1.AutoRotateOnEdgesBlockV1
Automatically deskew an image by finding the rotation angle that best aligns the image's dominant straight edges (e.g. the sides of a document, package, panel, or shelf) to the vertical axis, the horizontal axis, or whichever of the two is closest, then rotating the full-resolution image by that angle with an automatically expanded canvas so nothing is cropped.
How This Block Works¶
This block estimates the rotation angle from the image's dominant gradient orientation, then applies that rotation to the image. The block:
- Converts the image to grayscale (color images are converted with
BGR2GRAY) - Downscales a working copy so its largest dimension is at most
internal_resolutionpixels (default 1000, for speed; the detected angle is scale-invariant and is later applied to the full-resolution original) - Checks for a flat/low-texture image (very low pixel standard deviation) and, if
found, skips processing and returns the image unchanged with
angle = 0.0 - Enhances local contrast with CLAHE and applies a light Gaussian blur to reduce noise sensitivity, producing a float32 image used only for scoring candidate angles
- Computes Sobel gradients once and builds a magnitude-weighted histogram of gradient orientations (mod 180 degrees): gradients of the dominant lines point perpendicular to the lines themselves, so vertical lines concentrate the histogram around 0 degrees and horizontal lines around 90 degrees
- Rejects indistinct histograms (no clearly dominant orientation) and returns the image unchanged
- Refines the histogram's dominant mode with a doubled-angle weighted
circular mean over nearby orientations for sub-degree precision, and
normalizes the correction into
(-90, 90]degrees forvertical/horizontalor(-45, 45]degrees foreither - If the final angle is smaller in magnitude than
skip_below_degrees, returns the image unchanged withangle = 0.0(avoids unnecessary re-encoding/resampling for already-straight images). Likewise, if the final angle is larger in magnitude thanmax_correction_degrees, the image is returned unchanged withangle = 0.0- a correction beyond the plausible skew range usually means the search aligned to a different dominant structure (e.g. a long object silhouette) rather than the lines of interest - Otherwise rotates the full-resolution original image by the final angle around
its center, automatically expanding the output canvas so the entire rotated
image is preserved (matching the canvas-expansion behavior of
roboflow_core/image_preprocessing@v1's rotate task)
The block outputs both the deskewed image (with expanded canvas) and the applied rotation angle in degrees. Angles follow OpenCV's convention: positive angles rotate counter-clockwise.
Common Use Cases¶
- Document and Label Scanning: Straighten photographed documents, labels, or packaging before OCR or downstream detection, improving text and barcode reading accuracy
- Fixed-Camera Inspection: Correct small mounting-induced tilts in fixed-position industrial cameras so downstream measurement blocks (e.g. size or distance measurement) operate on axis-aligned imagery
- Conveyor and Shelf Alignment: Align images of conveyors, shelving, or panels whose edges should be vertical or horizontal, improving the reliability of downstream line/edge-based analysis
- Pre-processing for Detection Models: Straighten input images before running object detection or classification models that are sensitive to rotation
Connecting to Other Blocks¶
This block receives an image and produces a deskewed image plus the applied angle:
- Before detection or classification models to straighten images prior to inference, enabling more reliable model outputs on tilted source imagery
- Before measurement blocks (e.g. distance or size measurement) that assume an axis-aligned scene
- With downstream coordinate mapping - the
angleoutput (together with the original image's dimensions) fully determines the applied transform, so detections made on the rotated image can be mapped back into the original image's coordinate space by inverting the rotation matrix built bybuild_auto_rotate_matrix
Type identifier¶
Use the following identifier in step "type" field: roboflow_core/auto_rotate_on_edges@v1to add the block as
as step in your workflow.
Properties¶
| Name | Type | Description | Refs |
|---|---|---|---|
name |
str |
Enter a unique identifier for this step.. | ❌ |
target_orientation |
str |
Which edge direction the image's dominant straight lines should be aligned to. 'vertical' searches for the rotation that makes the dominant lines vertical, 'horizontal' searches for the rotation that makes the dominant lines horizontal, and 'either' aligns to whichever of the two is closest (search is limited to a +/-45 degree range around the nearest right angle).. | ✅ |
skip_below_degrees |
float |
If the detected correction angle's absolute value is smaller than this threshold (in degrees), the block returns the input image unchanged (identity passthrough) with angle = 0.0, avoiding unnecessary re-encoding/resampling of images that are already sufficiently straight.. |
✅ |
max_correction_degrees |
float |
If the best correction angle found exceeds this cap (in absolute degrees), the block returns the input image unchanged (identity passthrough) with angle = 0.0. Set this when the plausible skew range of your imagery is known (e.g. parts photographed at most ~40 degrees off-axis) so that a different dominant structure in the image (e.g. a long object silhouette instead of the lines of interest) cannot cause a wild, incorrect rotation. The default of 90.0 disables the cap.. |
✅ |
internal_resolution |
int |
The rotation-angle search runs on a working copy of the image downscaled so that its longest side is at most this many pixels; the full-resolution image is only used for the final rotation. Lower values make the search faster but can blur very thin lines; higher values preserve fine-line detail at the cost of search time.. | ✅ |
The Refs column marks possibility to parametrise the property with dynamic values available
in workflow runtime. See Bindings for more info.
Available Connections¶
Compatible Blocks
Check what blocks you can connect to Auto Rotate on Edges in version v1.
- inputs:
Google Gemini,OpenAI,Trace Visualization,Twilio SMS Notification,Pixel Color Count,Image Preprocessing,Anthropic Claude,Image Slicer,VLM As Classifier,Dynamic Crop,LMM For Classification,Object Detection Model,Bounding Box Visualization,Webhook Sink,Halo Visualization,Mask Visualization,Template Matching,Absolute Static Crop,Pixelate Visualization,Twilio SMS/MMS Notification,MoonshotAI Kimi,SIFT Comparison,Dot Visualization,Multi-Label Classification Model,Image Stack,Stitch Images,Stitch OCR Detections,OpenAI,OPC UA Writer Sink,Google Gemini,Stability AI Inpainting,Email Notification,Cosine Similarity,Distance Measurement,Frame Delay,EasyOCR,Keypoint Visualization,Llama 3.2 Vision,Florence-2 Model,Gaze Detection,LMM,Roboflow Custom Metadata,Auto Rotate on Edges,Image Slicer,Keypoint Detection Model,OCR Model,Circle Visualization,Model Comparison Visualization,Stability AI Outpainting,Slack Notification,Line Counter Visualization,Camera Calibration,Contrast Enhancement,Relative Static Crop,Single-Label Classification Model,Clip Comparison,Morphological Transformation,Email Notification,Halo Visualization,VLM As Detector,Cosmos 3,CogVLM,Polygon Visualization,Camera Focus,Corner Visualization,Ellipse Visualization,Qwen-VL,Crop Visualization,PP-OCR,Google Gemma,Qwen 3.5 API,PLC Writer,Model Monitoring Inference Aggregator,Morphological Transformation,Anthropic Claude,Roboflow Visual Search,Icon Visualization,Heatmap Visualization,Color Visualization,Instance Segmentation Model,Google Gemma API,OpenAI,CSV Formatter,Image Blur,Triangle Visualization,Background Color Visualization,Grid Visualization,Detection Event Log,Image Contours,Image Threshold,Blur Visualization,GLM-OCR,Current Time,Roboflow Visual Search Classifier,QR Code Generator,Anthropic Claude,OpenAI-Compatible LLM,Florence-2 Model,Reference Path Visualization,Polygon Zone Visualization,Stitch OCR Detections,Roboflow Asset Library Attributes,Classification Label Visualization,Microsoft SQL Server Sink,Perspective Correction,Background Subtraction,Camera Focus,Image Convert Grayscale,Label Visualization,Contrast Equalization,Polygon Visualization,Google Vision OCR,SIFT,Stability AI Image Generation,Text Display,Llama 3.2 Vision,Qwen 3.6 API,Line Counter,MQTT Writer,MoonshotAI Kimi,Roboflow Dataset Upload,Local File Sink,OpenRouter,Qwen3.5-VL,Roboflow Vision Events,Identify Changes,OpenAI,SIFT Comparison,Google Gemini,S3 Sink,Event Writer,Depth Estimation,Line Counter,Roboflow Dataset Upload - outputs:
SAM 3,Image Preprocessing,Single-Label Classification Model,Anthropic Claude,Image Slicer,CLIP Embedding Model,Dynamic Crop,Mask Area Measurement,BoT-SORT Tracker,Bounding Box Visualization,Mask Edge Snap,Object Detection Model,QR Code Detection,Absolute Static Crop,SIFT Comparison,Stitch Images,OpenAI,Instance Segmentation Model,Email Notification,Stability AI Inpainting,Frame Delay,Distance Measurement,EasyOCR,Llama 3.2 Vision,Track Class Lock,Florence-2 Model,Gaze Detection,Dynamic Zone,Auto Rotate on Edges,YOLO-World Model,Dominant Color,Keypoint Detection Model,Continue If,Stability AI Outpainting,Model Comparison Visualization,Line Counter Visualization,Camera Calibration,Single-Label Classification Model,Clip Comparison,VLM As Detector,CogVLM,SORT Tracker,Corner Visualization,PP-OCR,Camera Focus,Ellipse Visualization,Morphological Transformation,Detections List Roll-Up,Anthropic Claude,Roboflow Visual Search,Instance Segmentation Model,Color Visualization,OpenAI,Time in Zone,Triangle Visualization,Detections Stabilizer,Detection Event Log,Object Detection Model,Image Contours,SAM 3,Image Threshold,SAM 3,Barcode Detection,Roboflow Visual Search Classifier,Qwen2.5-VL,OpenAI-Compatible LLM,Florence-2 Model,Semantic Segmentation Model,SmolVLM2,Polygon Zone Visualization,Stitch OCR Detections,GeoTag Detection,Moondream2,VLM As Classifier,Camera Focus,Image Convert Grayscale,Label Visualization,Llama 3.2 Vision,Stability AI Image Generation,VLM As Detector,Perception Encoder Embedding Model,Instance Segmentation Model,MQTT Writer,Roboflow Dataset Upload,VLM As Classifier,Google Gemini,Event Writer,Semantic Segmentation Model,Depth Estimation,Seg Preview,Byte Tracker,Google Gemini,OpenAI,Trace Visualization,Pixel Color Count,SAM 3 Interactive,LMM For Classification,Object Detection Model,Velocity,Webhook Sink,Halo Visualization,Buffer,Mask Visualization,Template Matching,Twilio SMS/MMS Notification,Pixelate Visualization,MoonshotAI Kimi,Dot Visualization,Multi-Label Classification Model,Image Stack,OPC UA Writer Sink,Google Gemini,OC-SORT Tracker,Keypoint Visualization,LMM,Image Slicer,PTZ Tracking (ONVIF),OCR Model,Circle Visualization,Contrast Enhancement,Relative Static Crop,SAM2 Video Tracker,ByteTrack Tracker,Morphological Transformation,Halo Visualization,Clip Comparison,Cosmos 3,Polygon Visualization,Qwen-VL,Google Gemma,Crop Visualization,Qwen 3.5 API,Qwen3-VL,Qwen3.5,Keypoint Detection Model,Single-Label Classification Model,Icon Visualization,Heatmap Visualization,Motion Detection,Multi-Label Classification Model,Google Gemma API,Instance Segmentation Model,SAM3 Video Tracker,Image Blur,Background Color Visualization,Detections Stitch,Segment Anything 2 Model,Blur Visualization,GLM-OCR,Anthropic Claude,Reference Path Visualization,Classification Label Visualization,Google Vision OCR,Background Subtraction,Perspective Correction,Polygon Visualization,Contrast Equalization,SIFT,Qwen 3.6 API,Text Display,MoonshotAI Kimi,OpenRouter,Qwen3.5-VL,Roboflow Vision Events,OpenAI,Keypoint Detection Model,Multi-Label Classification Model,Roboflow Dataset Upload
Input and Output Bindings¶
The available connections depend on its binding kinds. Check what binding kinds
Auto Rotate on Edges in version v1 has.
Bindings
-
input
image(image): Input image (color or grayscale) to deskew. Color images are automatically converted to grayscale for angle detection; the detected rotation angle is applied to the full-resolution original image. The output includes both the rotated image (with an automatically expanded canvas) and the appliedanglein degrees..target_orientation(string): Which edge direction the image's dominant straight lines should be aligned to. 'vertical' searches for the rotation that makes the dominant lines vertical, 'horizontal' searches for the rotation that makes the dominant lines horizontal, and 'either' aligns to whichever of the two is closest (search is limited to a +/-45 degree range around the nearest right angle)..skip_below_degrees(float): If the detected correction angle's absolute value is smaller than this threshold (in degrees), the block returns the input image unchanged (identity passthrough) withangle = 0.0, avoiding unnecessary re-encoding/resampling of images that are already sufficiently straight..max_correction_degrees(float): If the best correction angle found exceeds this cap (in absolute degrees), the block returns the input image unchanged (identity passthrough) withangle = 0.0. Set this when the plausible skew range of your imagery is known (e.g. parts photographed at most ~40 degrees off-axis) so that a different dominant structure in the image (e.g. a long object silhouette instead of the lines of interest) cannot cause a wild, incorrect rotation. The default of 90.0 disables the cap..internal_resolution(integer): The rotation-angle search runs on a working copy of the image downscaled so that its longest side is at most this many pixels; the full-resolution image is only used for the final rotation. Lower values make the search faster but can blur very thin lines; higher values preserve fine-line detail at the cost of search time..
-
output
Example JSON definition of step Auto Rotate on Edges in version v1
{
"name": "<your_step_name_here>",
"type": "roboflow_core/auto_rotate_on_edges@v1",
"image": "$inputs.image",
"target_orientation": "vertical",
"skip_below_degrees": 0.4,
"max_correction_degrees": 45.0,
"internal_resolution": 1000
}