Load all the images from a directory

前端 未结 4 1725
慢半拍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
    
    0 讨论(0)
  • 2020-11-29 12:09

    I believe you want the imread function, not load. See the documentation.

    0 讨论(0)
  • 2020-11-29 12:21

    You can use the imageSet object in the Computer Vision System Toolbox. It loads image file names from a given directory, and gives you the ability to read the images sequentially. It also gives you the option to recurse into subdirectories.

    0 讨论(0)
  • 2020-11-29 12:22

    The full path (inc. directory) is not held in imgfiles.name, just the file name, so it can't find the file because you haven't told it where to look. If you don't want to change directories, use fullfile again when reading the file.

    You're also using the wrong function for reading the images - try imread. Other notes: it's best not to use i for variables, and your loop is overwriting I2 at every step, so you will end up with only one image, not four.

    0 讨论(0)
提交回复
热议问题