Background filling after rotation/deskew

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
HairyFotr
Posts: 1
Joined: 2013-01-02T10:18:16-07:00
Authentication code: 6789

Background filling after rotation/deskew

Post by HairyFotr »

Hi,
after I use -rotate or -deskew there are white corners in the image.
Example: http://imgur.com/8bZQ6

What I'd like to do is fill up those corners as best as possible... cropping is not an option.

I've quite like this solution I've found for rotation:
convert image.png -virtual-pixel Edge +distort SRT 10 out.png
Example: http://imgur.com/edMS0

But I'd also like something similar for -deskew. Any ideas how to do that?

So far the best I've come up with is using the border pixels...
Note: my implementation is wrong - it only takes the approximation of the left and right borders... it also uses some bash scripting.
convert image.png -background `convert image.png -resize 100x1! \( +clone -crop 1x1+0+0 \) +append -crop 2x1+99+0 -resize 1x1 txt:- | tail -1 | cut -b 30-50` -rotate 10 out.png
Example: http://imgur.com/4wDPO

So, any ideas how to best fill those pesky white corners, that also works with -deskew, and other transformations?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Background filling after rotation/deskew

Post by anthony »

Two solutions. Crop to just the internal area (ignore the outside parts), or somehow specify what it should be filled with.
EG background color (that is the white you see), or virtual-pixel specification (tiled, mirrored, edge replacated).

See Minor Photo Rotation
http://www.imagemagick.org/Usage/photos/#rotation
and Distort Affine Tiling
http://www.imagemagick.org/Usage/distorts/#affine_tile
with appropriate Virtual Pixel Methods
http://www.imagemagick.org/Usage/misc/#virtual-pixel
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply