matlab 为什么WriteMode和Append不起作用?

vm0i2vca  于 2022-11-15  发布在  Matlab
关注(0)|答案(1)|浏览(407)

MatLab

我正尝试在文件中保存多个图像,但它只保存了循环的第一个图像
我绑定了使用追加,但它不起作用
代码->imwrite(输出,文件夹,‘WriteMode’,‘append’)

完整代码:

img1 = imread("try1.pgm");
        img2 = imread( "try2.pgm");
    
    folder = "/Users/myname/Documents/MATLAB/TryImg.tif"
    folder=fullfile(folder,'img.tif')
    imwrite(img1,folder);
    imwrite(img2,folder,'WriteMode','append' );
vc9ivgsu

vc9ivgsu1#

问题已解决

1.通过对所有图像和文件使用.tif扩展名修复了无法识别的参数
1.(附加不起作用)通过在循环内使用spintf(‘%d.tif’,k);对每个图像使用不同的名称,如1.tif,2.tif,...
代码:

for k = 1:10
  % read the images from one file  
  jpgFilename = sprintf('%d.pgm', k);
  fullFileName = fullfile("filename", jpgFilename);
  if exist(fullFileName, 'file')
    imageData = imread(fullFileName );
  else
    warningMessage = sprintf('Warning: image file does not exist:\n%s', fullFileName);
    uiwait(warndlg(warningMessage));
  end
% then ,I did some process in the image 
% after process , save the image 
% find the file path to save the image inside it 
folderCover="/Users/myName/Documents/MATLAB/Cover.tif"
% make name for every image -> 1.tif , 2.tif , 3.tif , ...
jpgFilename = sprintf('%d.tif', k);
 fullFileNameCover = fullfile(folderCover, jpgFilename);
if k ==1  % first time to write 
imwrite(imageData,fullFileNameCover );
else 
imwrite(imageData,fullFileNameCover,'WriteMode','append')
end
end

相关问题