PNG Library Filed: Not a PNG File

Image Processing ToolBox, The function "imread" can not identify .png file. Why is this???

3 Commenti

ScottB
ScottB il 16 Ago 2024
You can try the command "imfinfo" on the file to see what is going on.
DGM
DGM il 16 Ago 2024
Modificato: DGM il 16 Ago 2024
You're explicitly instructing imread() to treat lotus.png as a PNG file, when it's apparently not a valid PNG file. The file may be damaged or misnamed.
If the file were a corrupted PNG, I would expect a more specific error message regarding what part of the decoding failed. That said, a grossly damaged file or a file with a damaged header may terminate with the given message. I'm not certain.
On the other hand, misnamed files are somewhat common. I've seen many people "convert" file formats by simply changing the file extension.
You typically don't need to specify the format explicitly. If you just give it the filename, imread() will inspect the file header in order to determine its actual format, regardless of what its extension is.
Otherwise, attach the file so that it can be inspected.
% this is a JPG which has been renamed incorrectly
% imread can figure that out on its own.
inpict = imread('misnamedjpg.png');
imshow(inpict)
% but if you force it to use the wrong decoder, it won't work.
inpict = imread('misnamedjpg.png','png');
Error using imread (line 444)
PNG library failed:
Not a PNG file
I second @ScottB's suggestion of using imfinfo to see what MATLAB thinks the file is (independent of the extension.) For the "png" file @DGM attached:
information = imfinfo('misnamedjpg.png')
information = struct with fields:
Filename: '/users/mss.system.9x72m/misnamedjpg.png' FileModDate: '16-Aug-2024 15:21:26' FileSize: 23509 Format: 'jpg' FormatVersion: '' Width: 512 Height: 384 BitDepth: 24 ColorType: 'truecolor' FormatSignature: '' NumberOfSamples: 3 CodingMethod: 'Huffman' CodingProcess: 'Sequential' Comment: {}
the Format field of the output correctly identified it as a JPG image. It will also tell you (via an error) if you give it something that's not an image, like a MATLAB code file.
cd(tempdir)
fid = fopen('timestwo.jpg', 'wt');
fprintf(fid, "function y = timestwo(x)\ny = 2*x;\n");
fclose(fid);
information2 = imfinfo('timestwo.jpg')
Error using imfinfo (line 146)
Unable to determine file format from filename.

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Convert Image Type in Centro assistenza e File Exchange

Prodotti

Release

R2023a

Richiesto:

霜
il 16 Ago 2024

Modificato:

DGM
il 16 Ago 2024

Community Treasure Hunt

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

Start Hunting!

Translated by