How to read multiple jpg images in matlab

i have 250 jpg images stored at in_dir = 'C:\Users\DJDJ\Desktop\pic';
these pictures are arranged as following and named : image1 , image2, image3.....image250
I want to read all these images and processing them starting by image1 after processing go to process image2 .and after image3.to..image250
then saved the resultant images after preproceesing in a specific file,for example at out_dir = 'C:\Users\DJDJ\Desktop\pic output';.
How can i do this in matlab?
thank you in advance

 Accepted Answer

Niels
Niels on 20 Jan 2017
Edited: Niels on 20 Jan 2017
you can use a for loop and save the image data in a cell:
replace png by the file type of your images. result will be a 1x250 cell array
for i= 1:250
x{i}=imread(['image',num2str(i),'.png'])
end
>> save('image_Data','x')

6 Comments

thank you for answering my question like this, the problem of reading the images as : image1 ,image2....image250 is solved. but i am trying to read them from in_dir = 'C:\Users\DJDJ\Desktop\pic' and after to save them in out_dir = 'C:\Users\DJDJ\Desktop\pic output';
  • * * * * * * * *
my prog is :
in_dir = 'C:\Users\DJDJ\Desktop\pic';
out_dir = 'C:\Users\DJDJ\Desktop\pic output';
for px = 1 : 250
fname=(['image',num2str(px),'.jpg']);
current_image = imread(fullfile(in_dir, fname,'jpg'));
% imshow(current_image);
% processing % out_image = some_function(current_image);
out_image = current_image ;
% save output
imwrite(out_image, fullfile(out_dir, fname,'jpg'));
end
i have Error in loadsaveimg (line 11)
current_image = imread(fullfile(in_dir, fname,'jpg'));
and what is the error? copy it pls
but as far as i can see you got an error because the jpg in your path come along twice in a row ( last argument 'jpg' in fullfile + in fname) the one in fullfile is wrong
replace line 11:
current_image = imread(fullfile(in_dir, fname));
You need to use exist() to verify that the file exists first. Also, splitting up long lines into multiple lines would make things simpler. Because of that, I can see that you totally ignored my answer to use the code in the FAQ and used your own code, thus causing your problems. I urge you to again look at the FAQ and see what it's doing that you aren't, and then the code will work.
Thank you very much for your assistance.Now,it's working well.
I have replaced line 11 by current_image = imread(fullfile(in_dir, fname));

Sign in to comment.

More Answers (1)

You would use the first code sample in this entry of the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F

2 Comments

Hi Image Analyst. Sorry maybe my comment has not related to this topic. I need your help please with Strehl Ratio. I have a point source image and need to find and draw the Strehl Ratio for it. I would high appreciate it if you could help me please. Very kind regards Maitham
Read this link and then attach your data in a new question. We can't do anything without data to work on.

Sign in to comment.

Categories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!