How to crop uneven image (with random black margins/spaces) automatically?

I'm making a code to stitch a set of images. When I transform the second image to fit the first using imwarp(), the output pixels outside the input image boundaries show as a consistent black or white color, so I get the stitched image which looks like this. When I have to stitch another image to this new panorama it causes a lot of problems.
Is there any way to crop this black outer portion to the axis I have shown automatically? By automatically I mean can I write a code that'll work for any image with such black outer regions.
imclearborder() just gives me an all black image.
But the answers makes no sense to me.

2 Comments

Can we always assume that the image on the left will be the smaller one and aligned with the axes?
The image on the right is warped and then stitched, so yes we can assume the one on the left is always aligned. But I don't think it will always be the smaller one...
Thanks!

Sign in to comment.

Answers (0)

Asked:

on 9 Jun 2015

Commented:

on 11 Jun 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!