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, with the following additions and defaults:
Background0background color to use
MaskingAllregion of interest
MethodAutomaticEdgeDetect method to use
Padding0padding of the original image
ResamplingAutomaticresampling method

Examples

Basic Examples (1) 

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/7bb0fa23-f949-414d-87f3-01f40cee1a8b"]
Out[1]=

Scope (2) 

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/289b2310-9092-463a-a95c-661cd27a4f8a"]
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/e9f886bc-abaf-46ea-b339-ff69a78ed86c"]
Out[3]=

Options (1) 

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/0f2b233f-6e57-4b0a-9b26-2822800ae480"]
Out[4]=

Publisher

Jon McLoone

Requirements

Wolfram Language 11.3 (March 2018) or above

Version History

  • 2.0.0 – 06 February 2020
  • 1.0.0 – 11 April 2019

License Information