Effacer les filtres
Effacer les filtres

How to generate multiple tiff files into my file path?

3 vues (au cours des 30 derniers jours)
AA
AA le 21 Mar 2024
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');

Réponses (2)

Chunru
Chunru le 21 Mar 2024
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 le 22 Mar 2024
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

Catégories

En savoir plus sur MATLAB Report Generator dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by