How to generate multiple tiff files into my file path?
6 次查看(过去 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!