How to save resized image with original filename to a folder.

Hi there,

I am trying to save a resized (smaller) image to a folder. I am doing image classification and having the resized images would be helpful.

I would like to store the resized images into a folder called “resized” or something like that.

Any thoughts? Thank you for any help you can offer.

Code below. Comments are from some of my trying to work it out myself.

clc
clear all
close all
load('Train_AlexNet_Feature')
load('Train_AlexNet_Label')
Test_AlexNet_Feature=[];
BT50=[];
mkdir('New Folder')
ds = imageDatastore('/Users/kimpitman/Documents/MATLAB/Vehicle/Test');
a=ds.Files;
for i=1:length(a)
[I,info] = readimage( ds , i);
g=imresize(I,[227,227]);
imshow(g)
net=alexnet;
net.Layers;
layer='fc7';
F=activations(net,g,layer,'outputAs','rows');
Test_AlexNet_Feature=[Test_AlexNet_Feature;F];
SVMModel=fitcsvm(Train_AlexNet_Feature,Train_AlexNet_Label,'KernelFunction','Linear');
[label,score]=predict(SVMModel,Test_AlexNet_Feature);
label=label;
if label(i,:)=='1'
display('This is BT-50')
BT=info.Filename
BT=string(BT);
BT50=[BT50;BT];
imwrite(g,fName(i),'.png');
%srcFiles = dir('/Users/kimpitman/Documents/MATLAB/Vehicle/Test'); % the folder in which ur images exists
%for i = 1 : length(srcFiles)
%filename = strcat('/Users/kimpitman/Documents/MATLAB/Vehicle/Testcopiedimages',srcFiles(i).name);
%im = imread(filename);
%newfilename=strcat('/Users/kimpitman/Documents/MATLAB/Vehicle/Testcopiedimages',srcFiles(i).name);
%imwrite(k,newfilename,'jpg');
%end
%end
%newfilename=ds.Files('/Users/kimpitman/Documents/MATLAB/Vehicle/Testcopiedimages',srcFiles(i).name);
%imwrite(g,newfilename,'jpg');
%imwrite(g,ds);
else
display('This is not BT-50')
BT=info.Filename
BT=string(BT);
BT50=[BT50;BT];
end
end
save('BT50')
T=table(BT50,label);
fname=sprintf('LinearTestMix159%s.xlsx',datestr(now, 'yyyymmddHHMM'));
writetable(T,fname,'Sheet',1)

ANSWER

Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.

Try This:

% Define input folder location.
folder = '/Users/kimpitman/Documents/MATLAB/Vehicle/Test';
% Create output folder name.
outputFolder = fullfile(folder, '/resized');
% Make output folder if it exists.
if ~isfolder(outputFolder)
mkdir(outputFolder)
end
ds = imageDatastore(folder)
% Loop over all files.
for k =length(ds.Files)
% Get this filename.
thisFileName = ds.Files{k};
fprintf('Processing %s...\n', thisFileName);
% Read in the input image.
originalImage = imread(thisFileName);
% Display it.
imshow(originalImage);
drawnow;

SEE COMPLETE ANSWER CLICK THE LINK

--

--

--

Simple! That is me, a simple person. I am passionate about knowledge and reading. That’s why I have decided to write and share a bit of my life and thoughts to.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Code Retreat, coding a break!

SEOR Public Beta Starts

Design Pattern Classifications Part 3— Behavioral Pattern

4 Gadgets for Jira to report specific-information about multiple projects in dashboards

Profields offers four different gadgets to embed them in Jira dashboards to report for multiple projects specific-information

🚀 Bamboo Panda Airdrop 📌Verified 🟢 Recommended 🌟🌟🌟🌟🌟

Create A S3 Bucket To Host a Static Website

Lead Enrichment using Elasticsearch

Hacking with Charles Proxy

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Technical Source

Technical Source

Simple! That is me, a simple person. I am passionate about knowledge and reading. That’s why I have decided to write and share a bit of my life and thoughts to.

More from Medium

End to End Machine Learning with H2O.ai

Character Encoding basics: A.S.C.I.I.

Move mlabel positions off axis

New TouchOSC Tutorial #3: Send Data to TouchDesigner with OSC (CHOP)