Reading multiple files from a folder and applying regionProps and saving co-ordinates
    3 views (last 30 days)
  
       Show older comments
    
Hi, 
I want to create bounding boxes around objects in an image and then store the co-ordinates of all the bounding boxes in the images in a table. 
For example, if I have 3 images with different amounts of bounding boxes in each image it should be stored as something like this:
image 1- [a1,b1,c1,d1; a2,b2,c2,d2; a3,b3,c3,d3; a4,b4,c4,d4]
image 2 - [a1,b1,c1,d1; a2,b2,c2,d2]
image 3 - [a1,b1,c1,d1; a2,b2,c2,d2; a3,b3,c3,d3 ]
etc. 
The problem I am having now is that only the last images bounding box co-ordinates are being stored in the array "prop". I understand that i should have some function to write these co-ordinates to this array but I am unsure of how to do this. 
They are also not being stored in the format as shown above. 
My code is shown below.
Any assistance would be greatly appreciated. 
Thanks!! 
Regards,
Kanu 
fileFolder = 'D:\Binary1';
dirOutput = dir(fullfile(fileFolder,'Pothole*.jpg'));
fileNames = {dirOutput.name};
for k=1:length(fileNames)
    H = fileNames{k};
    S = imread(fileNames{k});
    bn = imbinarize(S);
    imshow(bn)
    bn = bwareaopen(bn,100);
    imshow(bn);
    [L Ne]= bwlabel(bn);
    prop =regionprops(L);
    hold on
    for n = 1:length(prop)
        rectangle('Position',prop(n).BoundingBox,'EdgeColor','g','LineWidth',2);
    end
    hold off
    A = struct2cell(prop);
end
0 Comments
Answers (1)
  KALYAN ACHARJYA
      
      
 on 7 Aug 2019
        
      Edited: KALYAN ACHARJYA
      
      
 on 7 Aug 2019
  
      prop=cell(1,length(fileNames));
for .....
prop{k}=regionprops(L);
....
end
And prop retuen the cell array having the properties of all images one by one
>> prop
prop =
  1×n cell array %here n is the length of fileNames
   [255×1 struct]    [255×1 struct]   [255×1 struct]     [255×1 struct]     [255×1 struct].............
Here you can acess the properties of any images by simple calling prop, Say 
For 1st image prop{1}, 2nd image prop{2}...so on
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!