Resolve error in imread

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

Jan
Jan on 3 May 2015
Please format you code properly when you want others to read it. Thanks.
Please read this then fix this and all your other future and past posts (that we haven't already fixed). It will help everyone. Thanks.
Sorry, i am not getting.....what needs to be fixed here...??
Image Analyst
Image Analyst on 3 May 2015
Edited: Image Analyst on 3 May 2015
The code runs together. It doesn't look like what it does in MATLAB, does it? It's hard to read here. You don't just paste code in - did you see what the tutorial in the link I gave showed you? You have to paste the code in, then highlight it, and click the {}Code button at the top of the edit box to make it monospaced courier font and have the line wrapping be correct.
Jan
Jan on 3 May 2015
@harpreet: Don't you see that the code in your question is not readable due to the missing formatting?
@imageAnalyst, sorry for the inconvenience. Kindly check it now.
The imread command does not appear in the posted code. We do not know the contents of the file, which contains teh file names. What do you get as reply of:
[ImageName, GT] = textscan(fullfile(db_dir,DB,file_ground_truth), '%s %d');
What is the contents of ImageName?
The output for
[ImageName, GT] = textscan(fullfile(db_dir,DB,file_ground_truth), '%s %d')
is as follows:-
ImageName =
{1x1 cell} [0x1 int32]
GT =
88
Actually imageName is taken to be as a variable which can hold all the images of the dataset one by one using For loop.
imread command appeared in 'match_features' function. I think the root of the error is contents of the 'loc_file' or we can say imageName. loc_file should be an image, which is being passed to the function process_image.
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
@harpeet, did you get the solution for that error?

Sign in to comment.

Answers (1)

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

Asked:

on 3 May 2015

Answered:

on 19 Feb 2017

Community Treasure Hunt

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

Start Hunting!