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!