find an image in a big image
4 views (last 30 days)
Show older comments
I am trying to find a sample image patternC :
In my large image like :
To accomplish this task, i have coded this:
clc;
htm=vision.TemplateMatcher;
hmi = vision.MarkerInserter('Size', 10, ...
'Fill', true, 'FillColor', 'black', 'Opacity', 0.75);
% smallSubImage = fullfile(matlabroot, '\toolbox\images\imdemos\1.bmp');
% I = imread(smallSubImage);
I = imread('6.tif');
% Input image
I = I(:,:,:);
% Use grayscale data for the search
[rows, columns, numberOfColorChannels] = size(I);
if numberOfColorChannels == 3
I = rgb2gray(I);
if rows > 200 && columns > 200
I = I(1:rows,1:columns,:); % Crop all 3 channels.
end
else
if rows > 200 && columns > 200
I = I(1:rows,1:columns); % Crop single channel.
end
end
display(rows);
display(columns);
Igray = imread('patternC.tif');
[rows, columns, numberOfColorChannels] = size(Igray);
if numberOfColorChannels == 3
Igray = rgb2gray(Igray);
else
Igray = Igray(1:rows,1:columns); % Crop single channel.
end
% Use a second similar chip as the template
T = Igray;
% Find the [x y] coordinates of the chip's center
Loc=step(htm,Igray,T);
display(Loc);
display(NVALS);
display(NVALID);
% Mark the location on the image using Black disc
J = step(hmi, I, Loc);
imshow(T); title('Template');
figure; imshow(J); title('Marked target');
display('process completed');
But the output is:
The template is detected on the LEFT TOP corner(A Black Circle) of the image.
I am new in matlab. What is the matter here? Which things I have to take in mind?
5 Comments
Walter Roberson
on 21 Feb 2014
How could the output possibly be that? The date of the page changes, the QR code goes away, the list of digits along the left side got replaced by a linear barcode ???
Answers (0)
See Also
Categories
Find more on Display Image 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!