Wolfram Research

Function Repository Resource:

ImageLineLevel

Source Notebook

Rotate an image so that dominant lines are horizontal

Contributed by: Jon McLoone

ResourceFunction["ImageLineLevel"][img]

rotates image img so that dominant lines are horizontal.

ResourceFunction["ImageLineLevel"][img,n]

rotates image img so that dominant lines are horizontal using an EdgeDetect radius of n to find lines.

ResourceFunction["ImageLineLevel"][img,n,t]

rotates image img so that dominant lines are horizontal using EdgeDetect radius n and threshold t to find lines.

Details and Options

All options for ImageRotate are supported.
Background 0 background color to use
Masking All region of interest
Method Automatic EdgeDetect method to use
Padding 0 padding of the original image
Resampling Automatic resampling method

Examples

Basic Examples

Rotate an image so that its horizon is level:

In[1]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/a1e53808-2199-43c5-acd1-ea23bbc68b8e"]
Out[1]=

Scope

Where lines are not strong compared to texture, ImageLineLevel can fail to find the important lines:

In[2]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/d22bc343-1ab6-48a7-bec9-f3cfb3f60411"]
Out[2]=

Using the radius and threshold settings, as described for EdgeDetect, allows for better control of line detection:

In[3]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/080ee398-5868-43bf-9941-90af382eae18"]
Out[3]=

Options

All options of ImageRotate and EdgeDetect are supported. For example, the rotated image can be padded with reversed image contents:

In[4]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/5c13c023-99f7-448a-b0cb-cfaa616f9c58"]
Out[4]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Resource History

License Information