How to read a resized image?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Example -
B = imread('D.jpg');
A = imresize(B,0.5)
C = imread('A') - gives an error
0 Commenti
Risposte (2)
David Young
il 31 Gen 2015
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 Commenti
Image Analyst
il 31 Gen 2015
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 Commenti
Vedere anche
Categorie
Scopri di più su MATLAB Report Generator in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!