problem with a PGM file

7 vues (au cours des 30 derniers jours)
Fatma Gargouri
Fatma Gargouri le 22 Mar 2012
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
  1 commentaire
Fatma Gargouri
Fatma Gargouri le 23 Mar 2012
I don't understand the use of a PGM file and what it does it mean ?

Connectez-vous pour commenter.

Réponses (4)

John Labbate
John Labbate le 29 Juin 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');
Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.
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

lucy
lucy le 10 Avr 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?
  1 commentaire
Fatma Gargouri
Fatma Gargouri le 11 Avr 2012
yes that's what I meant!!

Connectez-vous pour commenter.


Walter Roberson
Walter Roberson le 10 Avr 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()

Juan Andrade
Juan Andrade le 14 Sep 2013
I am stuck in the same error, does anybody have some clue about it?, thanks

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by