[Digikam-devel] freerotation autocrop

Gerhard Kulzer gerhard at kulzer.net
Thu Jul 21 15:33:32 BST 2005


Hi Gilles,
> Le Mercredi 20 Juillet 2005 07:35 PM, Renchi Raju a écrit :
> > On Wed, 20 Jul 2005, Renchi Raju wrote:
> > > gilles, the code here shows how to do autocrop on freerotation:
> > >
> > > http://pooh.tam.uiuc.edu/digikam/freerotation.tar.bz2
> > >
> > > you might have to do some adjustments for negative angles.
> >
> > updated tarball to handle negative angles correctly.
>
> Your auto-crop method is simple but cannot be used to high rotation angle
> value. You crop the image not at the limit of rotated image border.
>
> This choose isn't optimum but is enough if angle is small. This case is
> generally true in photograph rotation correction and your method works
> fine. I had added this method in current Free Rotation plugin
> implementation.
>
> I have worked since 2 days to provide an optimized solution without sucess
> (:=))) . To calculate the efficient position of cropped area like describe
> before, there are complex trigonometric operations to do.
>
> If there is a mathematician in this room, you can try to solve this
> geometric problem (:=)))

I thought about your solution (with a pencil and a paper):
The problem can be formulated in different forms: 
a) find largest area rectangle without black corners
b) find widest rectangle without black corners
c) find a) keeping same width/height ratio, i.e. 4:3

For a) and c) the resulting rectangle has a slack sideways for 4:3 aspects 
(meaning it touches top and floor but not left and right). Per default you 
can place it into the centre. 

Solution:
original image h, w rotated by alpha; gamma is diagonal angle of aspect ratio, 
i.e. gamma=arctan(h/w)

new_width=h/cos(alpha)/[tan(gamma)+tan(alpha)]
new_height=new_width*tan(gamma)

Gerhard



More information about the Digikam-devel mailing list