problem with a PGM file

4 visualizzazioni (ultimi 30 giorni)
Fatma Gargouri
Fatma Gargouri il 22 Mar 2012
Risposto: John Labbate il 29 Giu 2022
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 Commento
Fatma Gargouri
Fatma Gargouri il 23 Mar 2012
I don't understand the use of a PGM file and what it does it mean ?

Accedi per commentare.

Risposte (4)

John Labbate
John Labbate il 29 Giu 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 il 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
Walter Roberson il 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()

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

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by