How to generate multiple tiff files into my file path?
조회 수: 5 (최근 30일)
이전 댓글 표시
I am trying to create a series of tiff files and am not sure why the following loops do not work.
thresholdarray = [0.01, 0.1, 0.001];
medfiltarray = [2, 8, 10, 16];
for i = 1:3
thresholdvalue = thresholdarray(1,i);
for j = 1:4
medfiltvalue = medfiltarray(1,j);
s1 = '4.04GFPthreshold:';
s2 = num2str(thresholdvalue);
s3 = 'medfilt:';
s4 = num2str(medfiltvalue);
s5 = '.tif';
tiffname = strcat(s1,s2,s3,s4,s5);
tiff = Tiff(tiffname,'a');
end
end
% why doesn't this code above work, but this code below generates a new tiff file in my file path?
tiff = Tiff('newtiff.tif','a');
댓글 수: 0
답변 (2개)
Chunru
2024년 3월 21일
thresholdarray = [0.01, 0.1, 0.001];
medfiltarray = [2, 8, 10, 16];
for i = 1:3
thresholdvalue = thresholdarray(1,i);
for j = 1:4
medfiltvalue = medfiltarray(1,j);
s1 = '4.04GFPthreshold_'; % <=== : -> _
s2 = num2str(thresholdvalue);
s3 = 'medfilt_'; % <===
s4 = num2str(medfiltvalue);
s5 = '.tif';
tiffname = strcat(s1,s2,s3,s4,s5);
tiff = Tiff(tiffname,'a');
end
end
dir
댓글 수: 0
Image Analyst
2024년 3월 22일
You cannot use colons in the file name (for Windows) unless it's immediately after a drive letter. Try this:
thresholdarray = [0.01, 0.1, 0.001];
medfiltarray = [2, 8, 10, 16];
% Read in a gray scale input image.
grayImage = imread('cameraman.tif');
subplot(1, 3, 1);
imshow(grayImage);
title('Original Image');
for thresholdIndex = 1 : 3
thresholdvalue = thresholdarray(1, thresholdIndex);
for filterIndex = 1 : 4
medFilterValue = medfiltarray(1, filterIndex);
% Create an output image.
% Do median filter on the gray scale image.
outputImage = im2double(medfilt2(grayImage));
subplot(1, 3, 2);
imshow(outputImage);
caption = sprintf('Median Filter of %d', medFilterValue);
title(caption)
% Now threshold it.
t = thresholdvalue * max(grayImage, [], 'all'); % Convert to gray levels.
outputImage = outputImage > t;
subplot(1, 3, 3);
imshow(outputImage);
caption = sprintf('Threshold Value of %.1f', t);
title(caption)
drawnow; % Force display to refresh immediately.
outputFileName = sprintf('4.04GFPthreshold %.3f_medfilt %d.tif', ...
thresholdvalue, medFilterValue);
outputFileName = fullfile(pwd, outputFileName); % Prepend folder.
fprintf('Now writing output file: "%s".\n', outputFileName);
% Write output file to disk
imwrite(outputImage, outputFileName);
end
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 3-D Volumetric Image Processing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!