Page 1 of 1

Snapping/rotating the image vertically

Posted: 2019-01-24T03:25:51-07:00
by mjamal
Hello Team,

Is there a way to snap/rotate the image vertically if it my image went out angled? Please see the attached image for more details.
Ie we need like, if I have an cropped image which is angled then system will automatically snap the image to make the longest line a vertical line, and snap the image accordingly from ImageMagick.

Image URL: https://www.dropbox.com/s/s2wa1wmm9u8he ... p.png?dl=0

I am using IM 7.0.8 version and OS is CentOS 7.6.
Please let me know if any one have any idea.

Thanks in advanced.

Re: Snapping/rotating the image vertically

Posted: 2019-01-24T06:26:21-07:00
by snibgo
This can be done with "-hough-lines", output to mvg. See viewtopic.php?f=4&t=25476 . From the coordinates of the endpoints of the longest line, a simple calculation gives the angle.

You need some pre-processing, and the image you supply isn't ideal for that. Do you have a version with a clearer foreground/background distinction?

Re: Snapping/rotating the image vertically

Posted: 2019-01-25T02:19:51-07:00
by mjamal
Please see the below url for the image which I need to snap/rotate vertically. Please let me know if that will be done from IM command?

https://www.dropbox.com/s/mc8axjfa865zj ... e.png?dl=0

Re: Snapping/rotating the image vertically

Posted: 2019-01-25T08:44:03-07:00
by snibgo

Code: Select all

magick angeledImage.png -alpha extract -threshold 50% -canny 0x1+10%+30% -hough-lines 9x9+400 mvg:-

# Hough line transform: 9x9+400
viewbox 0 0 983 2102
line 278.7,0 -16.7169,2102  # 521
The single line found is from (278.7,0) to (-16.7169,2102).

Trigonometry: angle = atan2 ( (278.7+16.7169), 2102) ) = 8 degrees.

Code: Select all

magick angeledImage.png -rotate -8 +repage out.png