필터 지우기
필터 지우기

How to generate multiple tiff files into my file path?

조회 수: 3 (최근 30일)
AA
AA 2024년 3월 21일
답변: Image Analyst 2024년 3월 22일
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');

답변 (2개)

Chunru
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
. 4.04GFPthreshold_0.001medfilt_2.tif 4.04GFPthreshold_0.01medfilt_2.tif 4.04GFPthreshold_0.1medfilt_2.tif .. 4.04GFPthreshold_0.001medfilt_8.tif 4.04GFPthreshold_0.01medfilt_8.tif 4.04GFPthreshold_0.1medfilt_8.tif 4.04GFPthreshold_0.001medfilt_10.tif 4.04GFPthreshold_0.01medfilt_10.tif 4.04GFPthreshold_0.1medfilt_10.tif 4.04GFPthreshold_0.001medfilt_16.tif 4.04GFPthreshold_0.01medfilt_16.tif 4.04GFPthreshold_0.1medfilt_16.tif

Image Analyst
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

카테고리

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

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by