I need to store these values from another function into an array
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
So this is my function which is calculating the number of keypoints from an image. So I have this file which has 8 images. I am comparing one of the image in the file with the others so I need to extract all the matching points between the images, and store those values of keypoints in an array for further processing.
SwSift is calling the function drawMatched that calculates the number of matched keypoints and prints it.
I am then accessing a folder of 8 images where I am matching one of the images with the rest.
I want to store these values in an array for further processing.
![matches.JPG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/259575/matches.jpeg)
function [] = drawMatched( matched, img1, img2, loc1, loc2)
% Function: Draw matched points
% Create a new image showing the two images side by side.
img3 = appendimages(img1,img2);
% Show a figure with lines joining the accepted matches.
figure('Position', [100 100 size(img3,2) size(img3,1)]);
colormap gray;
imagesc(img3);
hold on;
cols1 = size(img1,2);
n = size(matched,2);
colors = ['c','m','y'];
colors_n = length(colors);
for i = 1: n
if (matched(i) > 0)
color = colors(randi(colors_n));
line([loc1(i,2) loc2(matched(i),2)+cols1], ...
[loc1(i,1) loc2(matched(i),1)], 'Color', color);
end
end
hold off;
num = sum(matched > 0);
fprintf('Found %d matches.\n', num);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% this is another code that calls the function in which drawMatched has been used%%%%%
function keypoint = swSift(img1,img2)
% img1 = imread('1.jpg');
% img2 = imread('test.jpg');
[des1,loc1] = getFeatures(img1);
[des2,loc2] = getFeatures(img2);
matched = match(des1,des2);
% drawFeatures(img1,loc1);
% drawFeatures(img2,loc2);
drawMatched(matched,img1,img2,loc1,loc2);
global num
keypoint = num;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Calling this function in another window which I am accessing files in a folder, applying swSift %%%
% % and i am getting number of matched key points %%%%
clear all
clc;
location = 'E:\ATR\*.JPG'; % folder in which your template images exists
img= imread('E:\ATR\gh_368053_209864_19.JPG');
ds = imageDatastore(location); % Creates a datastore for all images in your folder
% fileNames={a.name};
while hasdata(ds)
temp = read(ds); % read image from datastore
% Image_name = temp.name;
% figure, imshow(temp)
keypoints = swSift(img,temp);
end
0 Kommentare
Antworten (1)
KALYAN ACHARJYA
am 3 Jan. 2020
Bearbeitet: KALYAN ACHARJYA
am 3 Jan. 2020
Jus considering num as output arguments in the function.
function num=drawMatched( matched, img1, img2, loc1, loc2)
% Function: Draw matched points
% Create a new image showing the two images side by side.
img3 = appendimages(img1,img2);
% Show a figure with lines joining the accepted matches.
figure('Position', [100 100 size(img3,2) size(img3,1)]);
colormap gray;
imagesc(img3);
hold on;
cols1 = size(img1,2);
n = size(matched,2);
colors = ['c','m','y'];
colors_n = length(colors);
for i = 1: n
if (matched(i) > 0)
color = colors(randi(colors_n));
line([loc1(i,2) loc2(matched(i),2)+cols1], ...
[loc1(i,1) loc2(matched(i),1)], 'Color', color);
end
end
hold off;
num=sum(matched > 0);
fprintf('Found %d matches.\n', num);
end
##
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% this is another code that calls the function in which drawMatched has been used%%%%%
function keypoint = swSift(img1,img2)
% img1 = imread('1.jpg');
% img2 = imread('test.jpg');
[des1,loc1] = getFeatures(img1);
[des2,loc2] = getFeatures(img2);
matched = match(des1,des2);
% drawFeatures(img1,loc1);
% drawFeatures(img2,loc2);
keypoint=drawMatched(matched,img1,img2,loc1,loc2);
end
##
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Calling this function in another window which I am accessing files in a folder, applying swSift %%%
% % and i am getting number of matched key points %%%%
clear all
clc;
location = 'E:\ATR\*.JPG'; % folder in which your template images exists
img= imread('E:\ATR\gh_368053_209864_19.JPG');
ds = imageDatastore(location); % Creates a datastore for all images in your folder
% fileNames={a.name};
l=1;
while hasdata(ds)
temp = read(ds); % read image from datastore
% Image_name = temp.name;
% figure, imshow(temp)
keypoints(l)= swSift(img,temp);
l=l+1;
end
keypoints
0 Kommentare
Siehe auch
Kategorien
Mehr zu Import, Export, and Conversion finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!