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.
Snapping/rotating the image vertically
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Snapping/rotating the image vertically
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?
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?
snibgo's IM pages: im.snibgo.com
Re: Snapping/rotating the image vertically
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
https://www.dropbox.com/s/mc8axjfa865zj ... e.png?dl=0
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Snapping/rotating the image vertically
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
Trigonometry: angle = atan2 ( (278.7+16.7169), 2102) ) = 8 degrees.
Code: Select all
magick angeledImage.png -rotate -8 +repage out.png
snibgo's IM pages: im.snibgo.com