how to store the image immediately after reading it in a for loop?

后端 未结 3 794
故里飘歌
故里飘歌 2021-01-25 02:07

I tried the following program for reading multiple images(about 300 images). Now I want to store these images immediately after reading each to some location by some name as

3条回答
  •  时光说笑
    2021-01-25 02:59

    I highly recommend that you store them in a cell array:

    for k=1:5
        image_path = ['C:\Users\shree\Desktop\1\im' num2str(i) '.jpg']; %// I have moved this to be on its own line as it will make debugging easier. You don't have to, but I think it's a good idea.
        images_all{k}  = imread(image_path);
    end
    

    By using eval to create variable names like g1, g2 etc you pollute your workspace with an unmanageable amount of variables. Plus if they are all in a cell array then it's really easy to apply the same function to each of them either in a loop or with cellfun.

    For example if you want to convert them all to greyscale now:

    images_grey = cellfun(@rgb2gray, images_all, 'UniformOutput', false);
    

提交回复
热议问题