PHD Discussions Logo

Ask, Learn and Accelerate in your PhD Research

Question Icon Post Your Answer

Question Icon

7 years ago in Matlab By Sapna C K

Store images in MATLAB

Is it possible to store images in a single array in MATLAB?

All Answers (2 Answers In All)

By Pradeep Sharma Answered 7 years ago

Yes. It is definitely possible to store images in single array or matrix in MATLAB.
myFolder = ‘C:Documents and SettingsyourUserNameMy DocumentsMy Pictures’;
if ~isdir(myFolder)
errorMessage = sprintf(‘Error: The following folder does not exist:n%s’, myFolder);
uiwait(warndlg(errorMessage));
return;
end
filePattern = fullfile(myFolder, ‘*.jpg’);
jpegFiles = dir(filePattern);
for k = 1:length(jpegFiles)
baseFileName = jpegFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, ‘Now reading %sn’, fullFileName);
imageArray = imread(fullFileName);
imshow(imageArray); % Display image.
drawnow; % Force display to update immediately.
end

By Fern G Answered 7 years ago

If you want to store images in cell array, use these:
clc;
clear all;
close all;
arr = cell(25,77); % Create Cell array
k = 1;
% get ‘zero’ 25 image cell array
img_folder = (‘E:4th yearProjectImagesChardatabaseSample0’); % Enter name folder and its path
filenames = dir(fullfile(img_folder,’*.jpg’)); % Read all image with specified extantion
Total_image = numel(filenames); % Count total image
for i=1:Total_image
j = 1;
for j=1:77
f = fullfile(img_folder,filenames(i).name); % Stroe ith image path
Output = imread(f); % read image
Output = imresize(Output,[11 7]);
Output = im2bw(Output);
Output = reshape(Output,[],77); % cell array divide by ’77’
Output = im2double(Output);
arr{k,j} = Output(1,j); % get all pixel value of ‘Output’ image
end
k = k+1;
end

Your Answer