Resolve error in imread

5 views (last 30 days)
harpreet
harpreet on 3 May 2015
Answered: Walter Roberson on 19 Feb 2017
I am trying to detect copy move image forgery using SIFT in the popular dataset of images called MICC-F220. My code is given below. It has some problem in assigning the path of the dataset images in the code. So, it is giving errors like:-
>> run_F220_experiment
Processing: C:\Users\parminder\Downloads\sift-forensic-master\sift-forensic-master\dataset\MICC-F220\C:\Users\parminder\Downloads\sift-forensic-master\sift-forensic-master\dataset\MICC-F220\groundtruthDB_220.txt (1/1)
Notice the path being repeated
Error using imread (line 350)
File
"C:\Users\parminder\Downloads\sift-forensic-master\sift-forensic-master\dataset\MICC-F220\C:\Users\parminder\Downloads\sift-forensic-master\sift-forensic-master\dataset\MICC-F220\groundtruthDB_220.txt"
*does not exist.*
Error in match_features (line 45)
im1=imread(filename);
Error in process_image (line 52)
[num p1 p2 tp] = match_features(imagefile, siftfile);
Error in run_F220_experiment (line 35)
countTrasfGeom = process_image(loc_file, metric, th, min_pts, 0);
My code is:-
% RUN EXPERIMENT
tstart = tic;
% dataset
DB = 'MICC-F220';
db_dir ='C:\Users\parminder\Downloads\sift-forensic-master\sift-forensic-master\dataset';
file_ground_truth = 'groundtruthDB_220.txt';
% parameters
metric = 'ward';
th = 2.2;
min_pts = 4;
% load ground truth from a file
[ImageName, GT] = textscan(fullfile(db_dir,DB,file_ground_truth), '%s %d');
num_images = size(ImageName,1);
fid_gt = fopen(fullfile(db_dir,DB,file_ground_truth));
C = textscan(fid_gt, '%s %u');
fclose(fid_gt);
TP = 0; % True Positive
TN = 0; % True Negative
FP = 0; % False Positive
FN = 0; % False Negative
for i = 1:num_images
%parfor i = 1:num_images % use for parallel computation (needs matlabpool)
loc_file = fullfile(db_dir,DB,cell2mat(ImageName{i}));
name = cell2mat(ImageName{i});
% process an image
fprintf('Processing: %s (%d/%d)\n',loc_file,i,num_images);
countTrasfGeom = process_image(loc_file, metric, th, min_pts, 0);
% tampering detection
dim_v=size(C{1,1});
for l=1:dim_v(1,1)
if isequal(C{1,1}{l},ImageName{i})
index=l;
end
end
if countTrasfGeom>=1
if C{1,2}(index)
TP = TP+1;
else
FP = FP+1;
end
else
if C{1,2}(index)
FN = FN+1;
else
TN = TN+1;
end
end
end
% compute performance
FPR = FP/(FP+TN);
TPR = TP/(TP+FN);
fprintf('\nCopy-Move Forgery Detection performance:\n');
fprintf('\nTPR = %1.2f%%\nFPR = %1.2f%%\n', TPR*100, FPR*100);
% compute computational time
tproc = toc(tstart);
tps = datestr(datenum(0,0,0,0,0,tproc),'HH:MM:SS');
fprintf('\nComputational time: %s\n', tps);
P.s- Localfile is not being assigned correct path so when i replace
loc_file = fullfile(db_dir,DB,cell2mat(ImageName{i}));
command, with this
loc_file = fullfile(cell2mat(ImageName{i}));
Then i get the following error:-
>> run_F220_experiment
Processing: C:\Users\parminder\Downloads\sift-forensic-master\sift-forensic-master\dataset\MICC-F220\groundtruthDB_220.txt (1/1)
Error using imread (line 363)
_ *Unable to determine the file format.* _
Error in match_features (line 45)
im1=imread(filename);
Error in process_image (line 52)
[num p1 p2 tp] = match_features(imagefile, siftfile);
Error in run_F220_experiment (line 35)
countTrasfGeom = process_image(loc_file, metric, th, min_pts, 0);
Please have a look on path assignment and figure out the mistakes.
  10 Comments
Walter Roberson
Walter Roberson on 9 Jan 2017
Naeem Hasan comments to harpreet:
@harpreet Have you solve your problem about forgery image detection if yes then please help me this is my final year project, I also have the same problem as you
kruthika shetty
kruthika shetty on 19 Feb 2017
@harpeet, did you get the solution for that error?

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 19 Feb 2017
The ground truth file appears to contain two columns, the first of which is intended to be a file name. In your file, the name read already happens to contain a full path, so your line
loc_file = fullfile(db_dir,DB,cell2mat(ImageName{i}));
is adding the project and directory on top of what is already a full path.
Your proposed line
loc_file = fullfile(cell2mat(ImageName{i}));
is closer but not exactly right. It should be
loc_file = ImageName{1}{i};
Now, the reason that the wrong file is being referenced by imread is that you have
[ImageName, GT] = textscan(fullfile(db_dir,DB,file_ground_truth), '%s %d');
That does not ask to read from the ground truth file: it asks to process the string constructed from fullfile(db_dir,DB,file_ground_truth) . textscan() can operate in two modes: if you pass it a file identifier as the first parameter then it reads from the given file, but if you pass it a string then it uses the string itself as the content to parse.
Your could should be
thisfile = fullfile(db_dir,DB,file_ground_truth);
fid = fopen(thisfile, 'rt');
if fid < 0; error('Ground truth file "%s" could not be opened', thisfile); end
[ImageName, GT] = textscan(fid, '%s %d');
fclose(fid);

Products

Community Treasure Hunt

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

Start Hunting!