error using load command to load images in PNG format

2 次查看(过去 30 天)
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?

回答(1 个)

Walter Roberson
Walter Roberson 2020-12-29
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 个评论
Image Analyst
Image Analyst 2020-12-29
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by