Deskew - remove added pixels

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Masejoer
Posts: 23
Joined: 2016-06-23T11:34:37-07:00
Authentication code: 1151

Deskew - remove added pixels

Post by Masejoer »

The handful of forum results don't help with this issue. I have an image that is being de-skewed by about 5%. This rotates the image and leaves solid colors where data didn't exist. I cannot seem to get auto-crop to work, at all.

Code: Select all

convert input -background black -set option:deskew:auto-crop 1 -deskew 40 output
I've tried:

Code: Select all

convert in.jpg -background green -set option:deskew:auto-crop 1 -deskew 40% -fuzz 5% -trim +repage out.jpg
Which doesn't work. I've used various auto-crop values with no luck. I just need the introduced-color to be completely removed after the deskew.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Deskew - remove added pixels

Post by fmw42 »

What is your IM version and platform? Please always provide that, since syntax differs. Can you post your image to some free hosting service so we can examine and test. You can then put the URL here.

Please read the topmost post in this forum at viewtopic.php?f=1&t=9620
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Deskew - remove added pixels

Post by fmw42 »

Masejoer wrote:The handful of forum results don't help with this issue. I have an image that is being de-skewed by about 5%. This rotates the image and leaves solid colors where data didn't exist. I cannot seem to get auto-crop to work, at all.

Code: Select all

convert input -background black -set option:deskew:auto-crop 1 -deskew 40 output
I've tried:

Code: Select all

convert in.jpg -background green -set option:deskew:auto-crop 1 -deskew 40% -fuzz 5% -trim +repage out.jpg
Which doesn't work. I've used various auto-crop values with no luck. I just need the introduced-color to be completely removed after the deskew.

Generally I use % for the deskew value, e.g. 40% to get reasonable results.

I made some tests and cannot get the auto-crop to work. See my bug report at viewtopic.php?f=3&t=30206#p135998

In my tests I found that a white background worked well with 40%, but a black background did not and needed 30% to work. So try other values for your green background.

try

Code: Select all

convert input -deskew XX% -fuzz YY% -trim +repage output
though that may leave some background. If so, then add -shave ZZxZZ after -trim, where XX is deskew percent, YY is a small fuzz percent and ZZ is in pixels.

Code: Select all

convert input -deskew XX% -fuzz YY% -trim +repage -shave ZZxZZ output
Masejoer
Posts: 23
Joined: 2016-06-23T11:34:37-07:00
Authentication code: 1151

Re: Deskew - remove added pixels

Post by Masejoer »

I'm running ImageMagick-7.0.1-6 Q16-x64 on Windows (.bat) and 7.0.2-5 Q16-x64 on Ubuntu (.sh).

Every time I try deskew xx% in Ubuntu, it fails to do anything, so I've been using the value without percent symbol. Maybe another bug.

Thanks for the bug report, fmw42.

Current image:
http://www.masejoer.com/Images/IM/testcheck22.jpg
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Deskew - remove added pixels

Post by fmw42 »

From my experience -deskew does not work well for angle above about 5% and probably not well also if the sides are not straight
Masejoer
Posts: 23
Joined: 2016-06-23T11:34:37-07:00
Authentication code: 1151

Re: Deskew - remove added pixels

Post by Masejoer »

fmw42 wrote:From my experience -deskew does not work well for angle above about 5% and probably not well also if the sides are not straight
I've had great luck running the deskew to get the images straight, and extremely angles (40 degrees) if I deskew twice. I just can't get good consistent cropping from the deskewed output - perspective distortion being the worst. I'm still amazed at how well imagemagick generally does on most things.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Deskew - remove added pixels

Post by fmw42 »

You could try my unperspective script if on Unix. Interesting about deskew twice. I have never tried that.
Masejoer
Posts: 23
Joined: 2016-06-23T11:34:37-07:00
Authentication code: 1151

Re: Deskew - remove added pixels

Post by Masejoer »

Does anyone know the real difference between "-deskew 40%" and "-deskew 40"? Some images deskew perfect with 40%, while others only deskew with "40". "40%" will just fail to deskew if it can't get a straight line, "40" will simply rotate the image a lot if not successful.
Post Reply