필터 지우기
필터 지우기

Changing file save name

조회 수: 2 (최근 30일)
no zoop
no zoop 2021년 2월 15일
이동: Voss 2024년 1월 2일
I have 10 images (collages), within each image there is anywhere from 20-200 smaller images. In total there are 3000 images between all 10 images.
Currently my code crops the small images from the collages and I know have 3000 images. When I save each of the small cropped image is saves it like... NAME%collage1%001, NAME%collage1%002,...,NAME%collage10%200.
I would like to save each of the small cropped images as... NAME%001, NAME%002,..., NAME%3000.
sum_blob = sum(numberOfBlobs) % I use this to get the sum of the number of blobs on each of the 10 collage images
message = sprintf('Would you like to crop out and save each individual images?');
reply = questdlg(message, 'Extract Individual Images?', 'Yes', 'No', 'Yes');
% Note: reply will = '' for Upper right X, 'Yes' for Yes, and 'No' for No.
if strcmpi(reply, 'Yes')
for n = 1 : non_binary_images
for k = 1 : numberOfBlobs(n) % Loop through all blobs.
% Find the bounding box of each blob.
thisBlobsBoundingBox = blobMeasurements{n}(k).BoundingBox; % Get list of pixels in current blob.
% Extract out this zoop into it's own image.
subImage = imcrop(OG_images{n}, thisBlobsBoundingBox);
% Saving the cropped image
folder = 'folder';
thisBaseFileName = sprintf('NAME%4d_%03d%.tif', n, k);
thisFullFileName = fullfile(folder, thisBaseFileName);
imwrite(subImage, thisFullFileName,'tif');
end
end
end

채택된 답변

dpb
dpb 2021년 2월 15일
이동: Voss 2024년 1월 2일
Just add a counting variable that is incremented inside the inner loop--
...
j=0;
for n = 1 : non_binary_images
for k = 1 : numberOfBlobs(n) % Loop through all blobs.
j=j+1;
...
thisBaseFileName = sprintf('NAME%04d%.tif', j);
...
  댓글 수: 2
no zoop
no zoop 2021년 2월 15일
이동: Voss 2024년 1월 2일
This is great! Thank you.
I did however find when using
'NAME%04d%.tif'
the second % ended up saving the images as a file instead of a tif, I fixed this by removing the second %.
'NAME%04d.tif'
dpb
dpb 2021년 2월 15일
이동: Voss 2024년 1월 2일
Yeah, just a typo in cleaning up existing format string...

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

추가 답변 (0개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by