error using load command to load images in PNG format
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a code to read and load variables of images in the JPG format (8bit) and it works.
This is the code :
function [frogformat ] = binned( imp )
%UNTITLED4 Summary of this function goes here
% Detailed explanation goes here
imread (imp,'png');
load (imp);
imp = sprintf (regexprep(imp,'.png', ''));
p = double(ans);
outputname = sprintf('%s', imp);
save (outputname,'p', imp);
when I change the format to PNG (16bit) I obtain the error:
Error using load
Number of columns on line 4 of ASCII file trial4.png must be the same as previous lines.
how can I solve this?
0 comentarios
Respuestas (1)
Walter Roberson
el 29 de Dic. de 2020
You cannot solve the problem. load() can never be used for png files.
It would take me some research to find an image file format that load() would not error on. load() is no designed to read images.
By the way: why do you read in the image and then throw away the data that was read, by not assigning the result of imread() to a variable and not asking to display the result of imread() ?
3 comentarios
Image Analyst
el 29 de Dic. de 2020
What does that code do? You failed to follow these important instructions:
%UNTITLED4 Summary of this function goes here
% Detailed explanation goes here
What's all that stuff about regexp and sprintf about? Looks like you want to overwrite your input file with something.
Like Walter says, simply use imread() if the extension is PNG or any other image extension.
[f, baseFilenameNoExt, ext] = fileparts(imp);
if strcmpi(ext, '.png')
theImage = imread(imp);
% Now do something with theImage, like pass it to imshow() or whatever.
end
Ver también
Categorías
Más información sobre Convert Image Type en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!