Combining image files into one array
Mostra commenti meno recenti
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.
Risposte (2)
Guillaume
il 11 Apr 2017
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 Commenti
Stephen23
il 11 Apr 2017
Note that you can get the correct order from the sequentially-numbered files by using my FEX submission natsortfiles:
Student_Coder
il 12 Apr 2017
Stephen23
il 12 Apr 2017
@Student_Coder: it seems like imagefiles is not a cell array. How did you generate imagefiles ?
Student_Coder
il 12 Apr 2017
Guillaume
il 12 Apr 2017
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 Commenti
Student_Coder
il 11 Apr 2017
KSSV
il 11 Apr 2017
files = dir('*tif') ;
iwant = cell(length(files),1) ;
for i = 1:length(files)
iwant{i} = files(i).name ;
end
iwant
Student_Coder
il 11 Apr 2017
KSSV
il 11 Apr 2017
Follow the same..inside the loop...read the image using imread
Categorie
Scopri di più su Image Segmentation and Analysis in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!