matlab trick
조회 수: 2 (최근 30일)
이전 댓글 표시
I have a folder which contain thousands of images, how can I load these image into a matrix with the size of (m,n,k), where m and n is the size of the image, k is the kth image. and I do not care the order of the image.
Thanks!
댓글 수: 0
답변 (2개)
Image Analyst
2012년 4월 27일
Preallocate a 3D image with the known number of files that you will be reading in. Then, inside the loop, insert the 2D image into the volumetric image as a slice (plane):
image3D(:,:,sliceNumber) = image2D;
댓글 수: 0
Kye Taylor
2012년 4월 27일
I'm assuming the images all have the same extension and that the file format is supported by imread. Also, I'm assuming that the current folder where your images are located is C:\myDir. You can change this in the code below.
folderOfInterest = 'C:\myDir'; % this is the path to your folder
cd(folderOfInterest); % make current folder your folder
ext = '.png'; % here's the extension of the images
files = dir; % get a listing of the current directory
% counts how many images are in current folder
isImageOfInterest = ~cellfun(@isempty,...
regexp(cellstr(char(files.name)),'.png','ignorecase'));
N = nnz(isImageOfInterest) ;
Images = cell(N,1);
cnt = 0;
for i = 1:length(files)
if isImageOfInterest(i)
cnt = cnt+1;
Images{cnt} = imread(files(i).name);
end
end
If all the images are the same size, you can create your three-dimensional matrix with the command
bigArray = cat(3,Images{:});
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!