Reading images from a file in MATLAB

I have bmp images in the image folder on my computer. I called it from 1.bmpto 100.bmp.

And I want to read these images as follows:

for i=1:100
    s='C:\images'+i+'.bmp';
    A=imread(s);
end

But Matlab made a mistake. How to implement this?

+3
source share
6 answers

You can use the function sprintf

s = sprintf('c:\images%d.bmp', i);
A = imread(s);

You can read more about string handling in matlab here.

+9
source

Create sas follows:

s = ['C:\images\' int2str(i) '.bmp'];

In addition, your loop will simply overwrite A, so you will have to make it a cell array in order to save all 100 images. Do this outside your loop:

A = cell(1,100);

:

A{i} = imread(s);
+5

. C:\images1.bmp. , , , , ypnos.

+3
imgfiles=dir('c:\images\*.*');
for k=1:length(imgfiles)
  ...
end 
+2

matlab .

files=dir('*.bmp') for k=1:numel(files) I=imread(files(k).name); end

.

+1
>  for i=1:100
>      s=strcat('C:\images',num2str(i),'.bmp');
>      try                                                  
>        A=imread(s);
>      catch
>      end 
>    end

num2str, , try aviod , , aviod .

0

Source: https://habr.com/ru/post/1713135/


All Articles