how to locate group of pixels in a large image

조회 수: 2 (최근 30일)
bidlee devi
bidlee devi 2020년 4월 26일
댓글: neil jerome 2020년 7월 28일
suppose i have a group of pixels arranged as
28 29 30 31
30 31 32 30
34 34 33 32
34 34 35 34
which has been cropped from a larger image.
Is there away to locate and find the exact group of pixels given above in the larger image?
I have cropped this particular set of pixels from a large image few months ago. My system got crashed and I dont remember the locations of these set of data.
Thanks! :)

답변 (1개)

neil jerome
neil jerome 2020년 7월 28일
%% find known submatrix in large matrix
% will find all instances
sourceMat = magic(15); % example source matrix
targMat = [218 10 27; 9 26 43]; % example target submatrix
[s1, s2] = size(targMat); % size of target
searchGrid = zeros(size(sourceMat,1)-s1, size(sourceMat,2)-s2); % grid of possible locations
for ii = 1:size(sourceMat,1)-s1 % loop over first dimension
for jj = 1:size(sourceMat,2)-s2 % loop over second dimension
subMat = sourceMat(ii:ii+s1-1,jj:jj+s2-1); % look at this region in source
diff = sum(squash(subMat - targMat)); % compare target to this region
if diff == 0 % is this region the same as target?
searchGrid(ii,jj) = 1; % record success!
end
end
end
[rows, cols] = find(searchGrid); % coordinate pairs of top corner of matching areas
horzcat(rows, cols)
  댓글 수: 2
Image Analyst
Image Analyst 2020년 7월 28일
You can use isequal:
% Not needed : diff = sum(squash(subMat - targMat)); % compare target to this region
% Compare current window with template using isequal().
if isequal(subMat, targMat) % is this region the same as target?
neil jerome
neil jerome 2020년 7월 28일
yep :)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Motor Drives에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by