Looping through 4 Images that have fixed names
조회 수: 3(최근 30일)
표시 이전 댓글
Hello. I have 4 images in memory that I want to loop through and perform some analysis on. I can't find a way to do this. The image names (that are held in memory) are always the same names.
IMList=app.IM1, app.IM2, app.IM3, app.IM4
Thanks
Jason
댓글 수: 0
채택된 답변
Bjorn Gustavsson
2021년 10월 26일
You can for example put the filenames into a cell-array:
imFileNames = {'im1.jpg','im2.png','im3.jpeg','im5.tiff'};
Then you can easily load the images one-by-one and do the single-image analysis on each:
for iIm = 1:numel(imFileNames)
currIm = imread(imFileNames{iIm});
results = fancy_img_processing(currIm);
end
HTH
댓글 수: 4
Bjorn Gustavsson
2021년 10월 27일
Sloppy reading by me, fortunately close enough for you to turn it into a solution!
추가 답변(2개)
the cyclist
2021년 10월 26일
IMList="app.IM"+(1:4)
creates a 1x4 string array, and then you can loop through that array to use the names.
댓글 수: 2
Bjorn Gustavsson
2021년 10월 26일
Then dont bother faffing about, simply put the filenames into a cell-array. See my answer.
Walter Roberson
2021년 10월 26일
IMList = {app.IM1, app.IM2, app.IM3, app.IM4};
nimg = length(IMList);
for K = 1 : nimg
IM = IMList{K};
app.ROI_C = IM; %or whatever
%more stuff
end
참고 항목
범주
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!