How to apply a common function to complete directory?

Hi,
I want to match and detect an input image with all images contained in a folder using for loop.
For this what i did is
srcFiles = dir('path of the folder');% the folder in which ur images exists
for i = 1 : length(srcFiles)
filename = strcat('path of the folder',srcfiles(i).name);
I = rgb2gray(imread(filename));
figure, imshow(I);
end
boxImage = rgb2gray(imread(' path of an input image');
figure;
imshow(boxImage);
title('Image of a Box');
for i = 1 : length(srcFiles)
boxPoints = detectSURFFeatures(boxImage);
scenePoints = detectSURFFeatures(I);
figure;
imshow(boxImage);
title('100 Strongest Feature Points from Box Image');
hold on;
plot(selectStrongest(boxPoints, 100));
title('300 Strongest Feature Points from I');
hold on;
plot(selectStrongest(scenePoints, 300));
[boxFeatures, boxPoints] = extractFeatures(boxImage, boxPoints);
[sceneFeatures, scenePoints] = extractFeatures(I, scenePoints);
boxPairs = matchFeatures(boxFeatures, sceneFeatures);
matchedBoxPoints = boxPoints(boxPairs(:, 1),:);
matchedScenePoints = scenePoints(boxPairs(:, 2),:);
figure;
showMatchedFeatures(boxImage, I,matchedBoxPoints, ...
matchedScenePoints,'montage');
title('Putatively Matched Points (Including Outliers)');
[tform, inlierBoxPoints, inlierScenePoints] = ...
estimateGeometricTransform(matchedBoxPoints, matchedScenePoints, 'affine');
figure;
showMatchedFeatures(boxImage, I, inlierBoxPoints, ...
inlierScenePoints, 'montage');
title('Matched Points (Inliers Only)');
boxPolygon = [1, 1;... % top-left
size(boxImage, 2), 1;... % top-right
size(boxImage, 2), size(boxImage, 1);... % bottom-right
1, size(boxImage, 1);... % bottom-left
1, 1]; % top-left again to close the polygon
newBoxPolygon = transformPointsForward(tform,boxPolygon);
newBoxPolygon1 = transformPointsForward(tform, boxPolygon);
figure;
imshow(I);
hold on;
x=line(newBoxPolygon(:, 1),newBoxPolygon1(:, 2), 'Color', 'g');
title('Detected Box');
end
This is the source code which i was tried, but i am not getting exact requirement. It is showing only one matched image from all images eventhough there are having some more similar images w.r.t an input image. can somebody help me?
Thanks in advance

답변 (1개)

Jan
Jan 2016년 3월 7일
The posted code will not display the wrong results, but it will not even run at all. There is at least a missing parenthesis.
srcFiles = dir('path');% the folder in which ur images exists
Are you aware, that you have to replace 'path' with the name of the folder you find the images in? Better:
Folder = <your folder comes here>
srcFiles = dir(Folder);% the folder in which ur images exists
for i = 1 : length(srcFiles)
filename = fullfile(Folder, srcfiles(i).name);
I = rgb2gray(imread(filename));
figure, imshow(I);
end
Now a lot of figures are opened. But I assume you want to include the rest of the processing in the loop also.
So omit:
boxImage = rgb2gray(imread('path'); % Line failes due to missing )
But use
boxImage = I;
and join both loops.

댓글 수: 1

Thank u so much for spending your valuable time on this question and for sharing answer.
And ya i am aware of writing folder name instead of path by replacing it. boxImage is used for reading an input image. So,how should i omit that line? Can you please understand the code and explain me in detail

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

카테고리

도움말 센터File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

질문:

2016년 3월 7일

편집:

2016년 3월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by