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!