How to read a resized image?
조회 수: 1 (최근 30일)
이전 댓글 표시
Example -
B = imread('D.jpg');
A = imresize(B,0.5)
C = imread('A') - gives an error
댓글 수: 0
답변 (2개)
David Young
2015년 1월 31일
You do not need to read A. It is already in memory. You can just do
C = A;
if you want to assign it to a new variable.
댓글 수: 0
Image Analyst
2015년 1월 31일
See what imprecise variable names causes? The badly named A is an image, not a filename string. imread() takes filename strings, not image arrays, so you can't pass it "A". If you had a descriptive name for your variable, you probably would have realized that.
Like David said, you already have the resized image in memory in variable "A" and if you want a copy of it in "C" you can just say C=A;. If you want to save A to disk, you can use imwrite, and then you would use the filename string in imread() to recall it from disk. But it's not necessary in this small script.
Better, more robust code would look like
originalImage = imread('D.jpg');
resizedImage = imresize(originalImage, 0.5); % Resize originalImage by half in each dimension.
% Save it to disk
baseFileName = 'Resized D.png';
folder = pwd; % Wherever you want to store it.
fullFileName = fullfile(folder, baseFileName);
imwrite(resizedImage, fullFileName);
% No need to create C at all.
% Now recall the resized image (say, in a different function or script)
baseFileName = 'Resized D.png';
folder = pwd; % Wherever you want to store it.
fullFileName = fullfile(folder, baseFileName);
% Check if it exists and read it in if it does, warn if it does not.
if exist(fullFileName , 'file')
smallImage = imread(fullFileName);
else
warningMessage = sprintf('Warning: file not found:\n%s', fullFileName);
uiwait(warndlg(warningMessage));
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 MATLAB Report Generator에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!