cropping 2 images together
Show older comments
My goal is to cut out similar regions from 2 images.
I’m using the example method shown in ‘normxcorr2()’ to find similar regions from two images, and am using ‘imcrop()’ to cut those areas.
What I want to ask is if there is a way to cut both images when the overlapping area doesn’t completely fit inside the larger image.
For example, I have 2 images ‘A’ and ‘B’ sized 1865*1200 and 904*670 respectively. And from the normxcorr2 function I get [xpeak=799, ypeak=846] and from that [xoffset=129, yoffset=-58]. This makes area [130 -57 670 904] to be the highest similarity, which is not inside ‘A’.
Is there a way to cut out the overlapping area from both ‘A’ and ‘B’ without the process of manually calculating the coordinates where they overlap?
Thank you in advance for your help.
7 Comments
darova
on 24 Feb 2020
as i understood you correctly

Red square is similar area you want to crop
Hoyong Yie
on 25 Feb 2020
Hoyong Yie
on 25 Feb 2020
darova
on 25 Feb 2020
Can you please attach the images and code?
Hoyong Yie
on 26 Feb 2020
darova
on 26 Feb 2020
You have white white background on each image. Did you try to get rid of it?

Hoyong Yie
on 26 Feb 2020
Accepted Answer
More Answers (1)
Image Analyst
on 26 Feb 2020
0 votes
You can probably determine where the peak of the cross correlation is. Then place a cropping box around that but you'll need to clip the coordinates of the box if the sides of the box go outside the image. Then use imcrop() or indexing with that (potentially cropped) box.
3 Comments
Hoyong Yie
on 28 Feb 2020
Edited: Hoyong Yie
on 28 Feb 2020
Image Analyst
on 28 Feb 2020
I said to "clip the coordinates" and "then use imcrop or indexing" and you said you're already doing that. OK, I didn't have a chance to look at your code yet - maybe this weekend. However you then said your question was about how to "clip the coordinates" and "crop", but you said you were already doing that. If you're already doing that, then why are they your questions??? So someone's confused (probably me).
Hoyong Yie
on 2 Mar 2020
Categories
Find more on Template Matching in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!