MATLAB: How to crop an image A which is a subset of an image B

Computer Vision ToolboxImage Processing Toolboxpattern recognitiontemplate matching

I have two images where image A is a subset of image B.I could with feature matching technique – identify, match and show the images as a pair. Now that i have identified and matched image A with image B. i want to clip out(crop) that exact region from image B and create a new image. How can i do this, any help is appreciated ?

Best Answer

If you have matched the points, then you can simply find the bounding box of the matched points:
points = round(matchedTarget.Location);
left = min(points(:, 1));
right = max(points(:, 1));
top = min(points(:, 2));
bottom = max(points(:, 2));
croppedImage = target(top:bottom, left:right, :);