error using load command to load images in PNG format
2 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Walter Roberson
on 29 Dec 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 Comments
Image Analyst
on 29 Dec 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
See Also
Categories
Find more on Convert Image Type in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!