problem with a PGM file
4 views (last 30 days)
Show older comments
hello
I want to execute the code proposed by David low for the SIFT detector http://www.cs.ubc.ca/~lowe/keypoints/
it bloked in this lines :
f = fopen('tmp.pgm', 'w');
if f == -1
ferror(f)
end
fclose(f);
and I get this error message :
??? Error using ==> ferror
Invalid file identifier. Use fopen to generate a valid file
identifier.
PS: I work with windows 7
Answers (4)
John Labbate
on 29 Jun 2022
Doubt anyone is still working on this exact issue, but it is worth noting that if you are getting errors relating to the inputted .pgm file, make sure that your inputted file has the correct header in the way your SIFT code will recognize it.
For example, I was using the ezSIFT code by robertwgh that can be found on Github. Outputting a .pgm from MATLAB gives a different format than the ezSIFT software could take, so I had to write a new function within the C++ ezSIFT code that would successfully parse the .pgm that came out of MATLAB.
The .pgm file that is put into the ezSIFT software MUST have pixels that are size 8-bit and be a type P5 .pgm file (this means the image data must be formatted in binary. You can use the code below to get the correct file type to output to use with ezSIFT.
imwrite(8bit_image_matrix, "output_filename.pgm",'Encoding','rawbits');
It also should be noted that the header of a .pgm always includes the following information in ASCII:
pgm magic number (for ex. P5)
image width image height
maximum pixel size
0 Comments
lucy
on 10 Apr 2012
i am also studying on this, it will create a pgm file for temporal use..
f = fopen('tmp.pgm', 'w');
if f == -1
error('Could not create file tmp.pgm.');
end
fprintf(f, 'P5\n%d\n%d\n255\n', cols, rows);
fwrite(f, image', 'uint8');
fclose(f);
do you mean this part?
Walter Roberson
on 10 Apr 2012
The -1 value returned on error is not a file identifier, and so cannot be used in the call to ferror()
Instead, use
[f, message] = fopen('tmp.pgm', 'w');
Then if f is -1 then "message" holds the error message you would get hope to get back from ferror()
0 Comments
Juan Andrade
on 14 Sep 2013
I am stuck in the same error, does anybody have some clue about it?, thanks
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!