Loop overwriting previous file

1 view (last 30 days)
Hi, I am trying to automate uncollaging collaged images. I have a folder with a bunch of collaged images that are already binary. When I run my loop and use regionprops it only ends up saving information for the last image in the folder... how do I fix this???
for n = 1:total_images_binary
binary_Images=fullfile(image_folder_binary, filenames_bin(n).name) ; % its will specify images names with full path and extension
our_images_binary = imread(binary_Images); % read images
labeledImage = bwlabel(our_images_binary,8); % Label each blob so we can make measurements of it
blobMeasurements = regionprops(labeledImage, our_images_binary, 'all');
numberOfBlobs = size(blobMeasurements, 1);
end
  2 Comments
no zoop
no zoop on 13 Sep 2019
continuation on this question.... I am trying to get the other properties on the image so I can crop them out, but again it only loops through the last image. I thought add the (n) to end of numberOfBlobs would help, but nothing
for k = 1 : numberOfBlobs (n) % Loop through all blobs.
% Find the mean of each blob. (R2008a has a better way where you can pass the original image
% directly into regionprops. The way below works for all versions including earlier versions.)
thisBlobsPixels = blobMeasurements(k).PixelIdxList; % Get list of pixels in current blob.
meanGL = mean(our_images_binary(thisBlobsPixels )); % Find mean intensity (in original image!)
meanGL2008a = blobMeasurements(k).MeanIntensity; % Mean again, but only for version >= R2008a
blobArea = blobMeasurements(k).Area; % Get area.
blobPerimeter = blobMeasurements(k).Perimeter; % Get perimeter.
blobCentroid = blobMeasurements(k).Centroid; % Get centroid one at a time
blobECD(n) = sqrt(4 * blobArea / pi); % Compute ECD - Equivalent Circular Diameter.
fprintf(1,'#%2d %17.1f %11.1f %8.1f %8.1f %8.1f % 8.1f\n', k, meanGL, blobArea, blobPerimeter, blobCentroid, blobECD(k));
end
Walter Roberson
Walter Roberson on 13 Sep 2019
blobECD(k) = sqrt(4 * blobArea / pi);
perhaps.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 13 Sep 2019
for n = 1:total_images_binary
binary_Images=fullfile(image_folder_binary, filenames_bin(n).name) ; % its will specify images names with full path and extension
our_images_binary = imread(binary_Images); % read images
labeledImage = bwlabel(our_images_binary,8); % Label each blob so we can make measurements of it
blobMeasurements = regionprops(labeledImage, our_images_binary, 'all');
numberOfBlobs(n) = size(blobMeasurements, 1);
end
  2 Comments
no zoop
no zoop on 13 Sep 2019
why does put the (n) after numberOfBlobs work? By using the (n) does it know to loop thru the other images?
Walter Roberson
Walter Roberson on 13 Sep 2019
(n) is indexing into an array. The first time around you write into numberOfBlobs(1), the second time into numberOfBlobs(2), then into numberOfBlobs(3), and so on.

Sign in to comment.

More Answers (0)

Categories

Find more on Images in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!