Load all the images from a directory

前端 未结 4 1751
慢半拍i
慢半拍i 2020-11-29 11:25

I have certain images in a directory and I want to load all those images to do some processing. I tried using the load function.

imagefiles = di         


        
4条回答
  •  醉酒成梦
    2020-11-29 12:07

    You can easily load multiple images with same type as follows:

    function Seq = loadImages(imgPath, imgType)
        %imgPath = 'path/to/images/folder/';
        %imgType = '*.png'; % change based on image type
        images  = dir([imgPath imgType]);
        N = length(images);
    
        % check images
        if( ~exist(imgPath, 'dir') || N<1 )
            display('Directory not found or no matching images found.');
        end
    
        % preallocate cell
        Seq{N,1} = []
    
        for idx = 1:N
            Seq{d} = imread([imgPath images(idx).name]);
        end
    end
    

提交回复
热议问题