How can I resize image for self-training
4 次查看(过去 30 天)
显示 更早的评论
Good day, I am novice with matlab. I am also novice with openmpi (cluster). We have some nodes on a cluster with Matlab and my boss asked to investigate my self to explain how it works :o| :o)....
My first goal is the following: With matlab on my personnal PC, 1) I would like to resize about 100 high resolution images from a source folder to a target foler. 2) I would like to count the time for that job.
My second goal is to move the matlab script to my cluster and to see hoe long does it take to resize 100 image, with one node, then four node (etc), ..and to learn about openmpi and matlab.
I would appreciate if you can help me with my first goal. Would you know a tutorial, a How to or example of code to 1) To read the images into a folder 1) To resize and copy images from a source folder and a target folder (the quality is not matter)
Many thank for any suggetsion and help
0 个评论
回答(4 个)
KSSV
2017-7-10
To read image check imread.
To resize image use imresize
You need to run a loop for each image to read and resize, for that check: https://in.mathworks.com/matlabcentral/answers/385-how-to-read-images-in-a-folder .There are many links for this, this is one among them.
To check the time elapsed or time taken, doc tic, toc , timeit
1 个评论
Walter Roberson
2017-7-10
For work on a cluster, see parfor()
Pierrot10
2017-7-10
1 个评论
Walter Roberson
2017-7-10
Accessing
files(m).name(end-3:end)
assumes that end-3 is a valid index into files(m).name . That is not true if name is less than 4 characters long, such as if you are examining the '.' or '..' entries.
files = dir('source');
files([files.isdir]) = []; %get rid of . and .. and all folders
for m = 1:numel(files)
thisfile = files(m).name;
[~, ~, ext] = fileparts(thisfile);
if strcmp(ext, '.jpg')
x = imread(thisfile, 'jpg');
% process x
end
end
Or you could just
files = dir(fullfile('source', '*.jpg');
files([files.isdir]) = []; %get rid of weirdly named folders
for m = 1 : numel(files)
thisfile = files(m).name;
x = imread(thisfile, 'jpg');
% process x
end
This works without a test because the dir() already restricted to .jpg files
Walter Roberson
2017-7-10
projectdir = 'source';
files = dir(fullfile(projectdir, '*.jpg'));
files([files.isdir]) = []; %get rid of weirdly named folders
for m = 1 : numel(files)
thisfile = fullfile(projectdir, files(m).name );
x = imread(thisfile);
% process x
end
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!