xcorr 2 max indexes

3 views (last 30 days)
michael scheinfeild
michael scheinfeild on 20 Oct 2014
hi i want to find the max index of corner i do 2 times xcorr 2 in the left i have good index while in the right not
*
a=imread('filename000.jpg');
b=im2bw(a);
borg=b;
se0=strel('line',5,0);
se1=strel('line',5,90);
bdil=imdilate(imdilate(b,se0),se1);
stats=regionprops(bdil,'MajorAxisLength','MinorAxisLength','FilledArea','PixelIdxList','PixelList');
MajorAxisLength = [stats.MajorAxisLength];
MinorAxisLength = [stats.MinorAxisLength];
FilledArea = [stats.FilledArea];
% PixelIdxList = [stats.PixelIdxList];
% PixelList =[stats.PixelList];
medMajorAxisLength = median(MajorAxisLength);
medMinorAxisLength = median(MinorAxisLength);
medFilledArea = median(FilledArea);
maxMajorAxisLength = max(MajorAxisLength);
maxMinorAxisLength = max(MinorAxisLength);
maxFilledArea = max(FilledArea);
idxAxisMajor = find(MajorAxisLength<0.5*(medMajorAxisLength+maxMajorAxisLength));
idxAxisMinor = find(MinorAxisLength<0.5*(medMinorAxisLength+maxMinorAxisLength));
idxArea = find(FilledArea<0.5*(medFilledArea+maxFilledArea));
idxEliminate = union(union(idxAxisMajor,idxAxisMinor),idxArea);
bcopy=bdil;
for(m=idxEliminate)
bcopy(stats(m).PixelIdxList)=0;
end
% second iteration
bcopyDil=imerode(imerode(bcopy,se0),se1);
stats=regionprops(bcopyDil,'MajorAxisLength','MinorAxisLength','FilledArea','PixelIdxList','PixelList');
MajorAxisLength = [stats.MajorAxisLength];
MinorAxisLength = [stats.MinorAxisLength];
FilledArea = [stats.FilledArea];
maxMajorAxisLength = max(MajorAxisLength);
idxEliminate = find(MajorAxisLength<maxMajorAxisLength);
bcopy=bcopyDil;
for(m=idxEliminate)
bcopy(stats(m).PixelIdxList)=0;
end
% more dilate
bdil=imdilate(imdilate(bcopy,se0),se1);
b=bdil;
%%template
n=150;
zleft=zeros(n);
zleft(1:n-2,2:3)=1;
zleft(n-3:n-2,2:end)=1;
zright=zeros(n);
zright(1:n-2,n-3:n-2)=1;
zright(n-3:n-2,1:end-2)=1;
%%match left
cc = xcorr2(double(b),double(zleft));
figure,imagesc(cc);title('left correlation');
[max_cc, imax] = max(abs(cc(:)));
[ypeak, xpeak] = ind2sub(size(cc),imax(1));
corr_offset = [ (ypeak-size(zleft,1)) (xpeak-size(zleft,2)) ];
hold on,plot(xpeak,ypeak,'ys')
yleft = corr_offset(1)+n-2;
xleft = corr_offset(2)+1;
figure(100),imshow(borg),hold on,plot(xleft,yleft,'rs');title('corr found edge')
%%match rigth
cc = xcorr2(double(b),double(zright));
figure,imagesc(cc);title('right correlation');
[max_cc, imax] = max(abs(cc(:)));
[ypeak, xpeak] = ind2sub(size(cc),imax(1));
corr_offset = [ (ypeak-size(zright,1)) (xpeak-size(zright,2)) ];
hold on,plot(xpeak,ypeak,'ys')
%%her i not recive the good index
yright = corr_offset(1)+n-2;
xright = corr_offset(2)+1;
% figure(100),imshow(b),hold on,plot(xleft,yleft,'rs');title('corr found edge')*

Answers (0)

Community Treasure Hunt

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

Start Hunting!