Clear Filters
Clear Filters

save images into folder

3 views (last 30 days)
Murstoe
Murstoe on 14 Apr 2020
Answered: Walter Roberson on 14 Apr 2020
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

Accepted Answer

Walter Roberson
Walter Roberson on 14 Apr 2020
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

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!