Combining image files into one array
古いコメントを表示
I have many image files that I am trying to combine into one column array/matrix. The file names are sequentially numbered. Each image file is about 200 x 200 pixels, grayscaled (values are 0 to 255), .tif files. I need the first file's contents to be read from left to right, and top to bottom, starting with row 1 column 1. The information from all image files needs to be ordered into one column, starting with the first file.
(There are more functions that I will be applying to each image, but I am having trouble coming up with an easy way to construct the final column matrix).
Thank you for the help.
回答 (2 件)
Guillaume
2017 年 4 月 11 日
imagefiles = {...}; %list of files to read, obtained any way you want, e.g. with |dir|, or |uigetfile|
imagevectors = zeros(200*200, numel(imagefiles));
for imageidx = 1:numel(imagefiles)
imagevectors(:, imageidx) = imread(imagefiles{imageidx}); %will fail if the image is not exactly 200x200
end
5 件のコメント
Stephen23
2017 年 4 月 11 日
Note that you can get the correct order from the sequentially-numbered files by using my FEX submission natsortfiles:
Student_Coder
2017 年 4 月 12 日
Stephen23
2017 年 4 月 12 日
@Student_Coder: it seems like imagefiles is not a cell array. How did you generate imagefiles ?
Student_Coder
2017 年 4 月 12 日
Guillaume
2017 年 4 月 12 日
As per the comment I wrote, the imagefiles cell array is supposed to contain the list of files to open. I.e. something like:
imagefiles = {'C:\somewhere\somename.tif'
'C:\somewhere\someothername.tif'
'C:\whereever\readme.tif'};
Your question seemed to be about how to read the files and then store them one by column. This is what I've answered.
However, you now seem to imply that you've already read the files as uint8. If you've already read the files, then how are they all stored in matlab. Whichever way (assuming it's not each in an individual variable), it's trivial to reshape and concatenate them as one column each.
files = dir('*tif') ;
for i = 1:length(files)
disp(files(i).name)
% do waht you want
end
4 件のコメント
Student_Coder
2017 年 4 月 11 日
KSSV
2017 年 4 月 11 日
files = dir('*tif') ;
iwant = cell(length(files),1) ;
for i = 1:length(files)
iwant{i} = files(i).name ;
end
iwant
Student_Coder
2017 年 4 月 11 日
KSSV
2017 年 4 月 11 日
Follow the same..inside the loop...read the image using imread
カテゴリ
ヘルプ センター および File Exchange で Image Segmentation and Analysis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!