It can't read an image, it says the path does not exist even though the path does exist
Show older comments
clc
close all
clear all
imgpath{4}= 'D:\MATLAB\Finger_Knuckle_Print_Original_Database\Left_Index_Finger_165\';
fd4=fopen('loglist_Left_Index.txt','rt'); % 294 subjects Train Total train = 493
feat1=[];
k=6;
for i=1:165
txt1=fscanf(fd4,'%s\n',1);
for j=1:6
fn1=sprintf('%s/%s index/0%iROI.jpg',imgpath{4},txt1,j); %u01000s0001_fnf1.jpg
img1=imread(fn1);
F=[]
H=slbp(img1);
F=[F;H(:)];
P=ridgelet(img1,0);
QQ=q(F,P);
feat_test=[ feat_test [reshape(QQ ( :,:,1 ) ,[ ],1 )] ];
end
end
3 Comments
Stephen23
on 4 Jun 2021
"it says the path does not exist..."
Most likely because that path does not exist.
"even though the path does exist"
How are you checking this?
Steven Lord
on 5 Jun 2021
You have asked this question 1, 2, 3, and 4 times and received answers and/or comments on three of those questions.
Asking the same thing multiple times is not necessarily likely to get you different answers. It's likely to get you the same answer multiple times.
Please pick one of these questions and continue the discussion in that one question. Please don't ask this a fifth time.
John D'Errico
on 5 Jun 2021
4 identical questions on the same day. I closed one of them.
Answers (2)
Nobody here can guess the contents of the index file you're reading or the actual filenames on your disk. You can start by generating a short list (e.g. 2 or 3) of the filenames assembled by fn1. Then go find the full path+filename+extension for those files. Do they differ? If so, why? It helps to paste them into a text file and look at them directly next to each other. It's easy to miss little details.
I said I couldn't guess, but I'll guess anyway. If you're running windows, directory separators are \, not ./. If you want, you can build the full path expression using fullfile(), which will automatically use whichever is appropriate. EDIT: see Stephen's comment below.
7 Comments
"If you're running windows, directory separators are \, not ./. "
Windows Explorer and APIs actually accept both forwardslash and backslash:
"except for COMMAND.COM, all other parts of the operating system accept both characters in a path..."
DGM
on 4 Jun 2021
Oh ... I didn't expect that'd work at all. All I know is that \ in path expressions doesn't work in Linux. I assumed it would be similar, but I don't have a Windows machine handy to test such an assumption.
ASMA MOHAMMAD
on 5 Jun 2021
Okay, but again, nobody knows what's on your disk. You're the only one who has access to that information. Did you compare this path expression to what's on disk? What did you see?
Try this example.
[fn pn] = uigetfile('*.*'); fullfile(pn,fn)
Run this in console, find the exact file you're looking for (01ROI.jpg). Select it, hit open. The path for that file will be dumped to the Matlab console. Compare it to the one you're calculating.
DGM
on 5 Jun 2021
Or strcmp() to enforce case-sensitivity.
Walter Roberson
on 5 Jun 2021
the code says Left_Index_Finger_165 but the error message says _left_index
Image Analyst
on 5 Jun 2021
You did not use the fullfile() function, and so you have a forward and backward slash next to each other creating a bogus filename.
"D:\MATLAB\Finger_Knuckle_Print_Original_Database\Left_Index_Finger_165\/_left index/01ROI.jpg"
^^
Bad Characters Here
Try this:
imgpath{4}= 'D:\MATLAB\Finger_Knuckle_Print_Original_Database\Left_Index_Finger_165';
fd4=fopen('loglist_Left_Index.txt','rt'); % 294 subjects Train Total train = 493
feat1=[];
k=6;
for k1 = 1 : 165
txt1=fscanf(fd4,'%s\n',1);
for k2 = 1 : 6
baseName = sprintf('%s index/0%iROI.jpg', txt1, k2); %u01000s0001_fnf1.jpg
fullFileName = fullfile(imgpath{4}, baseName)
img1=imread(fullFileName);
F=[]
H=slbp(img1);
F=[F;H(:)];
P=ridgelet(img1,0);
QQ=q(F,P);
feat_test=[ feat_test [reshape(QQ ( :,:,1 ) ,[ ],1 )] ];
end
end
28 Comments
Walter Roberson
on 5 Jun 2021
In Windows, \/ would be treated the same way as if you had used \\ or // at that point. Using more than one / or \ will be treated the same as a single slash, except that as the first two characters, two slashes introduces a UNC or long UNC https://en.m.wikipedia.org/wiki/Path_(computing)#Universal_Naming_Convention
ASMA MOHAMMAD
on 5 Jun 2021
Image Analyst
on 5 Jun 2021
Show me a screenshot with File Explorer's address bar showing the folder path, and your image file listed in the panel below so we can see for sure the actual folder and filename.
ASMA MOHAMMAD
on 5 Jun 2021
ASMA MOHAMMAD
on 5 Jun 2021
Image Analyst
on 5 Jun 2021
OK, note that your subfolders are like "001_left_index", not simply "index" like you were trying to use.
Please attach the file loglist_Left_Index.txt so we can get the data out of it.
Please give another screenshot inside one of those left_index folders so we can see the actual filenames.
I feel like we're getting somewhere though. Basically you're not constructing the filename properly.
Walter Roberson
on 5 Jun 2021
0%iROI.jpg probably needs to be %03dROI.jpg -- but we need to see the contents of one of the folders to be sure.
ASMA MOHAMMAD
on 5 Jun 2021
Walter Roberson
on 5 Jun 2021
When you are doing the fscanf(), the result you are getting int txt1 is empty, at a place that you are expecting to get something like '165_left' .
Please note that fscanf() does not automatically skip empty lines when you use a %s format. If you have a blank line at the top of the file, you would have problems. You should be testing ~isempty(txt1)
ASMA MOHAMMAD
on 5 Jun 2021
Image Analyst
on 5 Jun 2021
Right, because there is no " left_index" folder. There is a "001_left index" folder but no " left_index" folder. To be even more explicit, there is no underline after left like you put. And there is a 3 digit number and underline before "left" while you just have a space with no underline. You need to correct how you're building the file name.
And you forgot again to attach the file.
Please attach the file loglist_Left_Index.txt so we can get the data out of it.
ASMA MOHAMMAD
on 5 Jun 2021
Walter Roberson
on 5 Jun 2021
Sigh. Not 0%3dROI.jpg . Looking at one of your screenshots, you need %02dROI.jpg . Notice that there is no 0 before the % : the 0 must be between the % and the 2d .
But you also need to fix the directory name. If you look at the value of txt1 in your most recent screenshot you can see that it is empty, just as I warned you above.
You need to attach the loglist file here for us to use. Use the editor toolbar paperclip icon . You might need to zip the file first and attach the zip.
ASMA MOHAMMAD
on 5 Jun 2021
Walter Roberson
on 5 Jun 2021

And when the file chooser comes up, select loglist_Left_Index.txt and OK that. Then Submit the comment. This will result in the file being attached here for people to be able to examine. The exact details might be important, so even just having a picture of it might not be good enough.
ASMA MOHAMMAD
on 5 Jun 2021
Walter Roberson
on 6 Jun 2021
Edited: Walter Roberson
on 6 Jun 2021
That file appears to be empty. That would explain why txt1 comes out empty.
Image Analyst
on 6 Jun 2021
% Detect and avoid problems if our file does not have the required data in it.
d = dir('loglist_Left_Index.txt');
txt1 = fscanf(fd4, '%s\n');
if d.bytes < 3 || isempty(txt1)
errorMessage = sprintf('Warning: loglist_Left_Index.txt is empty!');
uiwait(errordlg(errorMessage));
return;
end
ASMA MOHAMMAD
on 6 Jun 2021
Image Analyst
on 6 Jun 2021
You need to edit the file 'loglist_Left_Index.txt' and put something into it, then save it.
ASMA MOHAMMAD
on 7 Jun 2021
Walter Roberson
on 7 Jun 2021
What is it that you need to have stored in a txt file?
If you are talking about loglist_Left_index.txt then you can use any text editor you like. You can also go to the command window in MATLAB and command
edit loglist_Left_index.txt
and use the MATLAB editor.
ASMA MOHAMMAD
on 7 Jun 2021
Walter Roberson
on 7 Jun 2021
Could you confirm that after you assign the results of the imread() to the variable img1 that you want to store the content of img1 to a text file? If so, then in what form? (And why ?)
Or are you needing to store the names of image files into the text file? Because if that is the case, is there any reason why you would want to read the file names from the text file, instead of just scanning to see which files exist at the time the code is run?
Image Analyst
on 7 Jun 2021
We're not talking about the image file. The image files are already saved in JPG image format files. You certainly don't want to store an image file (data) in a file that has a ".txt" file extension.
What we're talking about is a text file called "loglist_Left_index.txt" that you evidently think has something like one or more strings. These strings could be image file names, numbers, or whatever. You're the one who's opening the file so what do you think is in that text file? Why did you open the file since it seems like you don't know what's in it? Are you trying to use some code that someone else wrote but didn't get an example of that kind of text file it needs?
Walter Roberson
on 8 Jun 2021
The code is written to expect that loglist_Left_index.txt is a text file, in which there are several text lines. Each text line is expected to be the leading part of the name of a directory. Lines might be like
001_left
002_left
through to
165_left
The (repaired) version of the code would then append ' index' (space followed by the word index) to what was extracted from a line of the text file, putting the two together to form the name of a directory, such as 001_left index
The code then expects to look inside that directory to find files 01ROI.jpg 02ROI.jpg 03ROI.jpg 04ROI.jpg 05ROI.jpg
At present, you have the directories 001_left index to 165_left index and you have the 6 files inside each directory.
What you do not have at the moment is a file loglist_Left_index.txt with lines like I posted above.
At this point it is too frustrating going back and forth with you to encourage you to figure out how to create that file yourself, so I will post code that will create it for you.
Walter Roberson
on 8 Jun 2021
filename = 'loglist_Left_index.txt';
[fid, message] = fopen(filename, 'wt');
if fid < 0
error('Could not open file "%s" because "%s"', filename, message);
end
for K = 1 : 165
fprintf(fid, '%03d_left\n', K);
end
fclose(fid);
fprint('file "%s" created.\n', filename);
After running that, you should be able to run your code.
Walter Roberson
on 8 Jun 2021
Your code will need the line
baseName = sprintf('%s index/%02dROI.jpg', txt1, k2);
In particular the line must not have the underscore in it, and must not have the "left" in it. The "left" and the underscore are part of the text file you are reading.
Categories
Find more on Whos in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


