How can we read an image along with its .pts file one by one?
2 views (last 30 days)
Show older comments
sweety
on 19 May 2015
Commented: Walter Roberson
on 31 Jul 2016
I have face images along with their .pts file. I want to read face image one by one along with its .pts file.
I tried it. I am not getting any error in this code.
I just want to do this task using one for loop. So, I can read one face image along with its own .pts file (not all .pts files ) because if i will use two for loops in that case outside for loop will read first one image after that second for loop will read all .pts files,but i donot want this thing.
if true
% code
srcFiles = dir('E:\imagetest\*.jpg'); % the folder in which ur images exists
for j = 1 : length(srcFiles)
filename = strcat('E:\imagetest\',srcFiles(j).name);
I = imread(filename);
Filelist=dir('E:\TEST')% the folder in which .pts file exist
counter = 1;
FSize = size(Filelist);
for i=3:4%numel(Filelist)
filename = strcat('E:\TEST\',Filelist(i).name);
[FileId errmsg]=fopen(filename)
npoints=textscan(FileId,'%s %f',1,'HeaderLines',1);
points=textscan(FileId,'%f %f',npoints{2},'MultipleDelimsAsOne',2,'Headerlines',2)
Y=cell2mat(points);
end
end
end
%%Example of .pts file
version: 1
n_points: 4
{
115.947 221.239
121.382 250.566
130.001 279.096
141.677 306.538
}
0 Comments
Accepted Answer
Walter Roberson
on 19 May 2015
imgdir = 'E:\imagetest';
ptsdir = 'E:\TEST';
jpegwild = fullfile(imgdir, '*.jpg');
srcFiles = dir(jpegwild); % the folder in which ur images exists
for j = 1 : length(srcFiles)
imgfilename = srcFiles(j).name;
fullimgfilename = fullfile(imgdir,imgfilename);
[filepath, basename, ext] = fileparts(imgfilename);
fullptsfilename = fullfile(testdir, [basename '.pts']);
if ~exist(fullptsfilename,'file')
fprintf(2, 'Image "%s" did not have a corresponding .pts file\n", imgfilename);
continue;
end
I{j} = imread(fullimgfilename);
[FileId, errmsg] = fopen(fullptsfilename);
npoints = textscan(FileId,'%s %f',1,'HeaderLines',1);
points = textscan(FileId,'%f %f', npoints{2}, 'MultipleDelimsAsOne', 2, 'Headerlines', 2, 'CollectOutput, 1);
fclose(FileId);
Y{j} = points{1};
end
This forms the cell arrays I{k} being the k'th image and Y{k} being the corresponding points
3 Comments
Walter Roberson
on 31 Jul 2016
imshow(I{j})
hold on
scatter(Y{j}(:,1), Y{j}(:,2), 'r*');
hold off
More Answers (0)
See Also
Categories
Find more on Geometric Transformation and Image Registration in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!