How to read multiple images from a folder, perform a function and store all the values one by one in an array form?

조회 수: 2 (최근 30일)
Hey guys i am using the following code to read single image at a time, then performing few functions like the following
I=imread('1.bmp');
GLCM2=graycomatrix(I,'offset',[0 2],'symmetric',true);
stats2=GLCM_Features4(GLCM2,0);
t=struct2array(stats2);
When i run the above code i get the following result
In the same way i want to automate the process that can read the all images in the folder one by one and at the same time storing the values in the array. For example. In the following screenshot the first row in the array is the values calculated for Image(1.bmp). In the same way the code has to read image 2,image3,....image4,image99..and same time store the values in array as i pointed for image2.bmp and image3.bmp and so on..Please help me guys
  댓글 수: 2
Geoff Hayes
Geoff Hayes 2014년 6월 14일
Start with a for loop to iterate from 1 to 99 (or whatever the maximum number of images is). Assuming all your images are named as in your example, use sprintf to create the file name or something like
filename = [num2str(i) '.bmp'];
Do the work as above and then save the results to a matrix. Take the results of t and just concatenate it with the results from the previous iteration. Try it out and see what happens.
sai kiran thati
sai kiran thati 2014년 6월 14일
I am very new to Matlab Hayes. Could you write a sample program and explain it? Please

댓글을 달려면 로그인하십시오.

채택된 답변

Geoff Hayes
Geoff Hayes 2014년 6월 14일
Suppose you have 99 images and you want to process each one and save the results
n = 99; % number of images
statsMtx = []; % matrix for the stata data generated at each iteration
for i=1:n
filename = [num2str(i) '.bmp']; % create the filename give i
% now do what you have done already
% concatenate the new stats t into statsMtx
statsMtx =[statsMtx ; t];
end
Try the above and see what happens!
  댓글 수: 3

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2014년 6월 14일
This framework does exactly that: http://www.mathworks.com/matlabcentral/fileexchange/24224-magic-matlab-generic-imaging-component. Just plug your code into the AnalyzeSingleImage() function, and it handles the collection of results from all images and storing into an Excel workbook.

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by