PNG Library Filed: Not a PNG File
Mostra commenti meno recenti
Image Processing ToolBox, The function "imread" can not identify .png file. Why is this???

3 Commenti
ScottB
il 16 Ago 2024
You can try the command "imfinfo" on the file to see what is going on.
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');
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')
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')
Risposte (0)
Categorie
Scopri di più su Convert Image Type in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
