image - How to find more than one matching pattern using Normalized Correalation -
i'm using normxcorr2 find area match pattern , want find other area(in red rectangle) pattern. think works if can find next maximum , on , value must not in first maximum area or first 1 has been detected can't it. or if have idea using normxcorr2 find others area please advise me, don't have idea @ all.
here's code. modified 1 http://www.mathworks.com/products/demos/image/cross_correlation/imreg.html
onion = imread('pattern103.jpg'); %pattern image peppers = imread('rsz_1jib-159.jpg'); %original image onion = rgb2gray(onion); peppers = rgb2gray(peppers); %imshow(onion) %figure, imshow(peppers) c = normxcorr2(onion,peppers); figure, surf(c), shading flat % offset found correlation [max_c, imax] = max(abs(c(:))); [ypeak, xpeak] = ind2sub(size(c),imax(1)); corr_offset = [(xpeak-size(onion,2)) (size(onion,1)-ypeak)]; %size of window show of max value offset = corr_offset; xoffset = offset(1); yoffset = offset(2); xbegin = round(xoffset+1); fprintf(['xbegin = ',num2str(xbegin)]);fprintf('\n'); xend = round(xoffset+ size(onion,2));fprintf(['xend = ',num2str(xbegin)]);fprintf('\n'); ybegin = round(yoffset+1);fprintf(['ybegin = ',num2str(ybegin)]);fprintf('\n'); yend = round(yoffset+size(onion,1));fprintf(['yend = ',num2str(yend)]);fprintf('\n'); % extract region peppers , compare onion extracted_onion = peppers(ybegin:yend,xbegin:xend,:); if isequal(onion,extracted_onion) disp('pattern103.jpg extracted rsz_org103.jpg') end recovered_onion = uint8(zeros(size(peppers))); recovered_onion(ybegin:yend,xbegin:xend,:) = onion; figure, imshow(recovered_onion) [m,n,p] = size(peppers); mask = ones(m,n); = find(recovered_onion(:,:,1)==0); mask(i) = .2; % try experimenting different levels of % transparency % overlay images transparency figure, imshow(peppers(:,:,1)) % show red plane of peppers hold on h = imshow(recovered_onion); % overlay recovered_onion set(h,'alphadata',mask)
Comments
Post a Comment