# How to maximally crop a rotated image?

I'm cropping a rotated image, but I want to keep the ascect ratio fixed and not have any "extra" black pixels. Here's an example:

image = ExampleData[{"TestImage", "House"}];
rot = ImageRotate[image, 5 Degree]
ImageCrop[rot, {250, 200}]


But this isn't a good solution because it specifies the exact crop and I'm not sure what that will be generally. So really, what I want is the take a big of a crop as possible, preserving some given aspect ratio (which by default would be the same as the original image's asepect).

I would manually do it like this:

Details

• Please assume we know the exact angle of rotation and have the original unrotated image.
• Related:
• How do you feel about computing it from the morphological components? How fast does this need to be? One other option is to first pad with a very specific random color then find the bounding pixels with that color from the image data. Sep 18, 2017 at 20:50
• @b3m2a1 We should be able to compute it with basic geometry no?
– M.R.
Sep 18, 2017 at 20:50
• Oh if you know the rotation angle, sure. Take the corner points of a rectangle, rotate those, take the second from smallest left, second from largest right, or something. I was assuming you had randomly rotated images. Sep 18, 2017 at 20:51
• @b3m2a1 I don't think its that easy. See stackoverflow.com/questions/16702966/…
– M.R.
Sep 18, 2017 at 20:55
• Oh I missed the AspectRatio restriction. I see the complication now. Sep 18, 2017 at 21:09

Simply use the option "SameRatioCropping" in ImageRotate :
image = ExampleData[{"TestImage", "House"}];