Filter löschen
Filter löschen

Loop overwriting previous file

2 Ansichten (letzte 30 Tage)
no zoop
no zoop am 12 Sep. 2019
Kommentiert: Walter Roberson am 13 Sep. 2019
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 Kommentare
no zoop
no zoop am 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 am 13 Sep. 2019
blobECD(k) = sqrt(4 * blobArea / pi);
perhaps.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 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 Kommentare
no zoop
no zoop am 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 am 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Images finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by