How to access images(like Image1,Image2...)from a folder and pass through a code in Matlab?

4 views (last 30 days)
Kiran Das
Kiran Das on 3 May 2022
Commented: Kiran Das on 4 May 2022
I am doing my final year project. I have done a program to capture images and store it in a perticular folder(here it is FinalProject). I named those pictures like Image1,Image2,Image3..etc. Now i have written a programm to access the images one by one (like Iage1,Image2,Image3...etc). But it shows some errors. Please help me by retifying my code or put another solution. If any kind hearted person do that i will be thankfull to him /her.I have to submit my project at the end of third week of May,2022. I put my code. ThankYou.
for i=1:3
ImageFolder ='C:\Users\User\Desktop\FinalProject';
imgName = [ImageFolder,'\Image_',num2str(i),'.jpg'];
input_image = imread('C:\Users\User\Desktop\FinalProject\'\Image%d',num2str(i)','.jpg'');
Here its error:
Error: File: unknown.m Line: 4 Column: 95
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched

Accepted Answer

Jonas on 3 May 2022
the path creation is a mixture of multiple principles, one possibility is

More Answers (1)

DGM on 3 May 2022
You created a variable called imgName, but you're not using it.
input_image = imread(imgName,'.jpg');
Of course, since this loop displays each image with imshow() without pausing, you'll only see the last one. Only the last image will remain in memory, since input_image is overwritten each time.
You can preallocate a cell array or something and then load the images into a cell array instead.
numpicts = 3;
imagepile = cell(numpicts,1);
for k = 1:numpicts
ImageFolder ='C:\Users\User\Desktop\FinalProject';
imgName = [ImageFolder,'\Image_',num2str(k),'.jpg'];
imagepile{k} = imread(imgName,'.jpg');




Community Treasure Hunt

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

Start Hunting!

Translated by