Looping through 4 Images that have fixed names

1 次查看(过去 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

采纳的回答

Bjorn Gustavsson
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 个评论
Jason
Jason 2021-10-26
It is working once I change to this:
imList = {app.ROI_C,app.ROI_TL,app.ROI_TR,app.ROI_BL,app.ROI_BR};
Bjorn Gustavsson
Bjorn Gustavsson 2021-10-27
Sloppy reading by me, fortunately close enough for you to turn it into a solution!

请先登录,再进行评论。

更多回答(2 个)

the cyclist
the cyclist 2021-10-26
IMList="app.IM"+(1:4)
IMList = 1×4 string array
"app.IM1" "app.IM2" "app.IM3" "app.IM4"
creates a 1x4 string array, and then you can loop through that array to use the names.
  2 个评论
Jason
Jason 2021-10-26
Thankyou, but I'm sorry but I simplied my naming. My actual images are called:
app.ROI_C
app.ROI_TL
app.ROI_TR
app.ROI_BL
app.ROI_BR
Bjorn Gustavsson
Bjorn Gustavsson 2021-10-26
Then dont bother faffing about, simply put the filenames into a cell-array. See my answer.

请先登录,再进行评论。


Walter Roberson
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
  1 个评论
Jason
Jason 2021-10-26
Thanks Walter, but I had worked it out - sorry I I've already accepted the previous answer

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by