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?
댓글 수: 0
답변 (1개)
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
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 Center 및 File Exchange에서 Convert Image Type에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!