필터 지우기
필터 지우기

How can I identify an image inside of a larger image?

조회 수: 9 (최근 30일)
Andrew Padilla
Andrew Padilla 2018년 11월 11일
댓글: Image Analyst 2018년 11월 11일
I have two pictures. One is a small image of Waldo and the other is a much larger image with him hiding somewhere. My goal is to create a program that will find Waldo using only the functions length, size, imread, and image. This is what I have so far.
[row,column,layer] = size(Waldo);
[row_,column_,layer_] = size(wheresWaldo);
counter = 0;
for i = 1:1:row_
for j = 1:1:column_
for k = 1:1:layer_
if wheresWaldo(i,j,1) == Waldo(1,1,1) && wheresWaldo(i,j,2) == Waldo(1,1,2) && wheresWaldo(i,j,3) == Waldo(1,1,3)
counter = counter + 1;
ivals(counter) = i;
jvals(counter) = j;
end
end
end
end
What I am doing here is taking the first pixel of the Waldo image and seeing where the R G B values of that pixel occur in the wheresWaldo image. I found several instances and stores them in the variables ivals and jvals. ivals represent rows and jvals represents columns.

답변 (1개)

Image Analyst
Image Analyst 2018년 11월 11일
You can use normalized cross correlation with normxcorr2(), or you can use isequal() (if the small image and large image match exactly pixel for pixel). See attached demo.
  댓글 수: 2
Andrew Padilla
Andrew Padilla 2018년 11월 11일
편집: Andrew Padilla 2018년 11월 11일
Hi. Please take a look at my post again. I cannot use either of those functions. I listed the functions that I am allowed to use. I need to take advantage of for loops and if statements.
Image Analyst
Image Analyst 2018년 11월 11일
You will need the outer loops to scan your little image over the larger image. Then, at each location, you'll need another pair of loops to compare every pixel (all 3 colors) of the small image to the large image. So you're missing a pair of for loops.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by