how to locate group of pixels in a large image

4 vues (au cours des 30 derniers jours)
bidlee devi
bidlee devi le 26 Avr 2020
Commenté : neil jerome le 28 Juil 2020
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! :)

Réponses (1)

neil jerome
neil jerome le 28 Juil 2020
%% 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 commentaires
Image Analyst
Image Analyst le 28 Juil 2020
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 le 28 Juil 2020
yep :)

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by