how to clear this error???
2 views (last 30 days)
Show older comments
Attempted to access offset(1,:); index out of bounds because
size(offset)=[0,2].
Error in PydXcorr (line 40)
offset1 = [offset1;offset(1,:)];
Error in test (line 120)
[ybegin,xbegin,yend,xend] = PydXcorr(img22,temp11,2);
here my code.... function [ybegin,xbegin,yend,xend] = PydXcorr(img,tmp,level,thresh)
warning off;
if nargin == 3 thresh = 0.7; end
[Irows,Icolumns,Ilayers] = size(img); [Trows,Tcolumns,Tlayers] = size(tmp); % if is RGB, transform to GRAYSCALE if (Ilayers==3) img = rgb2gray(img); end if (Tlayers==3) tmp = rgb2gray(tmp); end
% time on hbar = waitbar(0,'Image matching'); tic;
% decomposition imgpyd = Decomposition(img,level); tmppyd = Decomposition(tmp,level);
% match in low resolution image
% calculate cross-correlation c = normxcorr2(tmppyd{level+1},imgpyd{level+1});
% get peak value and position [ymax,xmax] = find(abs(c)>thresh); offset = [ymax-size(tmppyd{level+1},1),... xmax-size(tmppyd{level+1},2)];
% delete repeated match point offset1 = []; offset1 = [offset1;offset(1,:)]; for n1 = 2:size(offset,1) m = 0; for n2 = 1:size(offset1,1) if (abs(offset(n1,1)-offset1(n2,1))>3 && ... abs(offset(n1,2)-offset1(n2,2))>3 ) m = m+1; end end if m == size(offset1,1) offset1 = [offset1;offset(n1,:)]; end end yoffset = offset1(:,1); xoffset = offset1(:,2);
% match in high resolution images
ii = level; while ii i = 1; n = length(yoffset); while i <= n % get the ROI yobj1 = 2*yoffset(i)-10; yobj2 = 2*yoffset(i)+size(tmppyd{ii},1)+10; xobj1 = 2*xoffset(i)-10; xobj2 = 2*xoffset(i)+size(tmppyd{ii},2)+10; if yobj1<=0 yobj1 = 1; end if xobj1<=0 xobj1 = 1; end if yobj2>size(imgpyd{ii},1) yobj2 = size(imgpyd{ii},1); end if xobj2>size(imgpyd{ii},2) xobj2 = size(imgpyd{ii},2); end objarea = imgpyd{ii}(yobj1:yobj2,xobj1:xobj2);
% match in ROI
c = normxcorr2(tmppyd{ii},objarea);
[max_c,imax] = max(abs(c(:)));
if max_c > thresh
[ypeak,xpeak] = ind2sub(size(c),imax(1));
corr_offset = [ypeak-size(tmppyd{ii},1),...
xpeak-size(tmppyd{ii},2)];
offset = corr_offset;
yoffset(i) = offset(1)+2*yoffset(i)-10-1;
xoffset(i) = offset(2)+2*xoffset(i)-10-1;
i = i+1;
else
yoffset(i) = [];
xoffset(i) = [];
n = n-1;
end
end
ii = ii-1;
end
% get the offset in the source image ybegin = yoffset; yend = yoffset+size(tmppyd{1},1)-1; xbegin = xoffset; xend = xoffset+size(tmppyd{1},2)-1;
% time off toc; close(hbar);
0 Comments
Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!