Cannot get Imagemagick "Deskew" to work - ideas?

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
WP58I
Posts: 3
Joined: 2019-02-01T04:08:42-07:00
Authentication code: 1152

Cannot get Imagemagick "Deskew" to work - ideas?

Post by WP58I »

I am relatively new to Imagemagick but have successfully done the install in Ubuntu.

I have a question re: deskew, which I cannot get to work.

The situation:-
- Scanned 35 mm transparancies,
- These have Black borders of various sizes which I need to remove. – they are fuzzy to various degrees - AND the degree of blackness vs the edge of the photo varies hugely
- They are also skewed by random small amounts – and this is the issue.

… I cannot deskew the photos.

I can run commands such as this

mogrify -fuzz 35% -deskew 80% -trim +repage *.jpg


… which deals to some extent with the detection of fuzzy edges (I have to vary the fuzz value a bit), but what every deskew value I try… no actual deskew happens.

Any ideas what I am doing wrong?

Sample image here

https://www.dropbox.com/s/yuapprbv32jzw ... 9.jpg?dl=0

(Note this is a jpg just for this exercise as it’s easier to play with smaller files…)

Any ideas anyone?

My thoughts so far:-
Do we need to specify Imagemagick to only look for features to deskew at the edge of the photos?
There is also the issue with the contrast of the black border vs the edge of the photo – in a generally bright photo this will be high but in a dark scene the contrast is low so Imagemagick may have difficulty in picking up edges.
This is actually already evident in the trimming as I have to vary the fuzz value to avoid some photos being over or under trimmed.
So would it be a good idea for the first operation to do some sort of gamma adjustment to enhance the edge/photo contrast to artificially increase the contrast, then reverse this at the end?

(Just in case anyone wonders why I am resaving lossy jpgs, I am really dealing with uncompressed tifs but it’s much easier to experiment with small filesize jpgs…)

Many thanks
WP58I
Posts: 3
Joined: 2019-02-01T04:08:42-07:00
Authentication code: 1152

Re: Cannot get Imagemagick "Deskew" to work - ideas?

Post by WP58I »

Anyone?

Thanks!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Cannot get Imagemagick "Deskew" to work - ideas?

Post by fmw42 »

Deskew does not work well on this type of image. It works better with text images or images with a constant background color. It also does not work well for angles above about 5 deg. I have tried a number of things to work around the issues, but am not having any success.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Cannot get Imagemagick "Deskew" to work - ideas?

Post by fmw42 »

-deskew seems to work better with a white background so that it has more contrast against the edges of the image. So this is about the best that I can do.

Code: Select all

convert img.jpeg -fuzz 12% -fill white -draw "color 0,0 floodfill" -alpha off tmp.png

convert tmp.png -background white -deskew 40% -format "%[deskew:angle]" info:
1.08396

convert img.jpeg -background black -rotate 1.08396 result.png
One of the big issues is that you have a sky colored line above the image. Also the background is not a constant color. Also harder to process when you have JPG format since it is lossy compression and the background is then not a constant value.


Please always provide your IM version, date, and platform/OS
WP58I
Posts: 3
Joined: 2019-02-01T04:08:42-07:00
Authentication code: 1152

Re: Cannot get Imagemagick "Deskew" to work - ideas?

Post by WP58I »

Many thanks!
I'll have go with this when I have time at the end of next week.

The originals are tifs so hopefully better than jpgs

Of course I have a real mixture of photos, some where the edge of the photo itself is almost black eg in shadow, so detecting the edge here will be the most difficult!
Post Reply