Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to keep the whole image after rotation (without cropping to the original size)? #181

Open
bearpaw opened this issue Aug 6, 2016 · 1 comment

Comments

@bearpaw
Copy link

bearpaw commented Aug 6, 2016

I found that the implementation of rotation forces the size of the rotated image as the same as the source image. Is it possible to keep the full rotated image (as the second cat image)? Thanks.

cat
cat

@bearpaw
Copy link
Author

bearpaw commented Aug 7, 2016

Well, I got a solution here for your reference

require 'image'

l = image.lena()
a = 30 * math.pi / 180
s = math.sin(a)
c = math.cos(a)
h = l:size(2)
w = l:size(3)
hh = math.floor(h*(c+s-1)/2)
ww = math.floor(w*(c+s-1)/2)

src = torch.zeros(3, h*(s+c), w*(s+c))
src[{{},{hh,hh+h-1},{ww,ww+w-1}}] = l
dst = image.rotate(src, a)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant