save images into folder

1 回表示 (過去 30 日間)
Murstoe
Murstoe 2020 年 4 月 14 日
回答済み: Walter Roberson 2020 年 4 月 14 日
hi guys, I have this problem i have been trying to fix without any success. I would be grateful if you could give it a look.
I have few images (4) all named like this: a_484 , a_485, a_486, a_487. All images are the same.
The first part of the script works just fine but i cant save the new images as i would like.
for example: let's say for each image matlab generates the picture of 10 bouding boxes. I would like to save those bounding box images in a new folder likewise: a_484_1, a_484_2, a_484_3, a_484_4, ..., a_484_10 - a_485_1, a_485_2, a_485_3, etc etc for each of them.
I will attach my script.
dirName = uigetdir('./', 'Select data folder');
cd(dirName);
for i=484:487 % numero layers esaminati
image_{i}=imread(sprintf('a_%03d.tif',i));
BW=image_{i}>3500;
figure,imshow(BW);
labeledImage = bwlabel(BW);
measurements = regionprops(labeledImage, 'BoundingBox', 'Area');
for k = 1 : length(measurements)
thisBB = measurements(k).BoundingBox;
image2_{i}=imcrop(image_{i},[thisBB(1),thisBB(2),thisBB(3),thisBB(4)]);
[rows cols depth]=size(image2_{i});
if rows*cols>100
figure,imshow(image2_{i});
colormap (jet)
colorbar
caxis([0 45000]);
axis on
end
end
baseFileName = sprintf('a_%03d_%k.tif', i, k);
fullFileName = fullfile('C:...\new', [baseFileName, num2str(i),'.tif']);
imwrite(image2_{i},fullFileName)
end

採用された回答

Walter Roberson
Walter Roberson 2020 年 4 月 14 日
baseFileName = sprintf('a_%03d_%k.tif', i, k);
fullFileName = fullfile('C:...\new', [baseFileName, num2str(i),'.tif']);
%k is not a valid % sequence. You should be using
baseFileName = sprintf('a_%03d_%d.tif', i, k);
fullFileName = fullfile('C:...\new', baseFileName);
but with C:...\new replaced with something meaningful

その他の回答 (0 件)

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by