필터 지우기
필터 지우기

save images into folder

조회 수: 3 (최근 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개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by