MATLAB Answers

Translated by

このページのコンテンツは英語から自動翻訳されています。自動翻訳をオフにする場合は「<a class="turn_off_mt" href="#">ここ</a>」をクリックしてください。

Bashir
1

How to store images in a single array or matrix

Bashir
さんによって質問されました 2013 年 5 月 27 日
最新アクティビティ Lav Palve
さんによって 回答されました 2019 年 1 月 21 日
Hello, i have a number of jpeg images stored in a folder; how can i read all the images and store them as a single matrix or array (reserving the image format).

  0 件のコメント

サインイン to comment.

4 件の回答

回答者: Image Analyst
2013 年 5 月 27 日
 採用された回答

Straight out of the FAQ:
myFolder = 'C:\Documents and Settings\yourUserName\My Documents\My 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 %s\n', fullFileName);
imageArray = imread(fullFileName);
imshow(imageArray); % Display image.
drawnow; % Force display to update immediately.
end
Obviously, you can adapt as needed, because I'm not sure what you mean when you say "store them as a single matrix". There is a montage() function that will do that if that's what you want. It will stitch together all the image files into one giant image.

  16 件のコメント

Image Analyst
2017 年 5 月 13 日
If you have the same question, see my answer to the same question. And I don't know much if anything about self organizing map neural networks.
One thing to look out for with montage() is that it requires all of the pictures to be of the same dimensions. But thanks anyways!
Another thing that could be useful is imageSet() Maybe this could work.

サインイン to comment.


回答者: Azzi Abdelmalek
2013 年 5 月 27 日

f=dir('*.jpg')
files={f.name}
for k=1:numel(files)
Im{k}=imread(files{k})
end

  10 件のコメント

Image Analyst
2017 年 2 月 14 日
Try this:
thisImage = cellArrayOfImages{23};
thisImage = double(rgb2gray(thisImage));
medFiltered = medfilt2(thisImage, [3,3]);
diffImage = someOtherImage - medFiltered;
Anjali S
2017 年 10 月 27 日
I am facing the same problem. I tried above code so my all images are now stored in matrix having size 1*6. Every cell is storing size of image (1*48000 due to resize)But I want every row should store actual bits of image and not the size. That is I want to store each image as a one row for creating training dataset. Ex my image is of 200*240 so I resized to 1*48000 . First row of the matrix should have 48000 columns like that matrix size will be 6 * 48000. I REQUEST KINDLY HELP ME ..
hey man, i have exactly the same problem. I have many images and want to make a matrix out of it. Have you solved your problem? if so can you share what you did? thanks in advance!

サインイン to comment.


回答者: Shelly Smith 2017 年 2 月 15 日
編集済み: Image Analyst
2017 年 2 月 15 日

Hey
I have a problem and will be grateful if someone help me. I am reading 200 images through this code:
folder = 'C:\Users\whatever'
filePattern = fullfile(folder, '*.pgm');
f=dir(filePattern)
files={f.name}
for k=1:numel(files)
fullFileName = fullfile(folder, files{k})
cellArrayOfImages{k}=imread(fullFileName)
imshow(cellArrayOfImages{k});
end
I get a row vector with 200 length. In each cell there's a 50x50 uint8 image. I need to have the elements value of 50x50 image as well. So I want to basically read all the images (200 images) and stored the value of all images in a matrix. Can anyone tell me how can I do that? Thanks in advance.

  1 件のコメント

Image Analyst
2017 年 2 月 15 日
I don't understand the question. You are reading in 200 images, which are 50 x 50 uint8 images, and storing them. It seems to be doing what you are asking for, so what's the problem? Do you want a 2-D array of cells instead of a 1-D row vector of cells? If so, why? And how many rows and columns do you want?

サインイン to comment.


回答者: Lav Palve
2019 年 1 月 21 日

Store images in cell array
clc;
clear all;
close all;
arr = cell(25,77); % Create Cell array
k = 1;
% get 'zero' 25 image cell array
img_folder = ('E:\4th year\Project\Images\Chardatabase\Sample0'); % 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

  0 件のコメント

サインイン to comment.



Translated by