- _ _At first, I used "normxcorr2" to find a same part of an image in another one, but in some cases this method failed to findingRelated code is:
f=100;
S=imcrop(Image1,[f*2 f*2 f f]);
L = bwlabel(S);
s = regionprops(L,'PixelIdxList');
max_value = zeros(numel(s), 1);
for k = 1:numel(s)
max_value(k) = max(S(s(k).PixelIdxList));
end
bright_objects = find(max_value > 100);
s=ismember(L, bright_objects);
c = normxcorr2(s,Image2);
[ypeak, xpeak] = find(c==max(c(:)));
yoffSet = ypeak-size(S,1)
xoffSet = xpeak-size(S,2)
hFig = figure;
hAx = axes;
imshow(Image2,'Parent', hAx);
imrect(hAx, [xoffSet+1, yoffSet+1, size(S,2), size(S,1)]);
S2=imcrop(Image2,[max(xoffSet)+1 max(yoffSet)+1 size(S,2)-1 size(S,1)-1]);
And it's work correctly(it has been shown in below image).
- so I have to use control points to improve this approach. Now i want to use control points for the same way, but the main problem that exist is I didn't know how to determine coordinate of control points in original Image and then display them in it by code ?! note that "cpselect" command select the control points by hand! please look at this part of code:
scale = 1;
J = imresize(Image1, scale);
theta = 90;
distorted = imrotate(J,theta);
ptsOriginal = detectSURFFeatures(Image2);
ptsDistorted = detectSURFFeatures(distorted);
[featuresOriginal, validPtsOriginal] = extractFeatures(Image2, ptsOriginal);
[featuresDistorted, validPtsDistorted] = extractFeatures(distorted, ptsDistorted);
indexPairs = matchFeatures(featuresOriginal, featuresDistorted);
matchedOriginal = validPtsOriginal(indexPairs(:,1));
matchedDistorted = validPtsDistorted(indexPairs(:,2));
x1 = matchedDistorted.Location(1,1)
y1 = matchedDistorted.Location(1,2)
S22=imcrop(Image2,[x1 y1 size(S,2)-1 size(S,1)-1]);
Indead by using this code, the control points coordinate determined but I want to display matched area in Image2. how can I find coordinate to crop this founded area?I think [x1,y1] isn't true and problem is here. Do you have any idea?
And it acts wrong(it has been shown in below image).