在 MATLAB 中以 .tif 格式保存图像
Saving image in .tif format in MATLAB
我无法以 .tif 格式保存多个名称不同的图像。
这是我当前的代码:
srcFiles = dir('path/*.tif');
for i = 1 : length(srcFiles)
img = strcat('path/',srcFiles(i).name);
img = imread(img);
figure, img = imshow(img(:,:,3));
colormap gray;
a = strcat(srcFiles(i).name, '-run.tif');
imwrite(img, a,'tiff');
end
我收到以下错误:
Error using imwrite (line 420)
Expected DATA to be one of these types:
numeric, logical
Instead its type was matlab.graphics.primitive.Image.
我知道我没有保存图像数组。但是,我不确定如何执行此操作,因为我必须调用 colormap gray
。此外,我使用 imwrite
执行此操作,因为这消除了手动保存时保存的 白色边框 。有什么想法吗?
在接下来的 3 行中,您正在更改变量的类型 img
:
这里是一个字符数组:
img = strcat('path/',srcFiles(i).name);
接下来是数值数组(一张图片):
img = imread(img);
最后是图形句柄:
figure, img = imshow(img(:,:,3));
为了保存此图像,您需要为 imwrite
提供 数字数组 ,最佳做法是为这些变量使用不同的名称,例如:
imgname = strcat('path/',srcFiles(i).name);
img = imread(imgname);
figure, imghandle = imshow(img(:,:,3));
我无法以 .tif 格式保存多个名称不同的图像。 这是我当前的代码:
srcFiles = dir('path/*.tif');
for i = 1 : length(srcFiles)
img = strcat('path/',srcFiles(i).name);
img = imread(img);
figure, img = imshow(img(:,:,3));
colormap gray;
a = strcat(srcFiles(i).name, '-run.tif');
imwrite(img, a,'tiff');
end
我收到以下错误:
Error using imwrite (line 420)
Expected DATA to be one of these types:
numeric, logical
Instead its type was matlab.graphics.primitive.Image.
我知道我没有保存图像数组。但是,我不确定如何执行此操作,因为我必须调用 colormap gray
。此外,我使用 imwrite
执行此操作,因为这消除了手动保存时保存的 白色边框 。有什么想法吗?
在接下来的 3 行中,您正在更改变量的类型 img
:
这里是一个字符数组:
img = strcat('path/',srcFiles(i).name);
接下来是数值数组(一张图片):
img = imread(img);
最后是图形句柄:
figure, img = imshow(img(:,:,3));
为了保存此图像,您需要为 imwrite
提供 数字数组 ,最佳做法是为这些变量使用不同的名称,例如:
imgname = strcat('path/',srcFiles(i).name);
img = imread(imgname);
figure, imghandle = imshow(img(:,:,3));