[英]Using MATLAB to save a montage of many images as one large image file at full resolution
I am trying to save a montage of many (~500, 2MB each) images using MATLAB function imwrite, however I keep getting this error: 我正在尝试使用MATLAB函数imwrite保存许多(〜500个,每个2MB)图像的蒙太奇,但是我不断收到此错误:
Error using imwrite>validateSizes (line 632)
Images must contain fewer than 2^32 - 1 bytes of data.
Error in imwrite (line 463)
validateSizes(data);
here is the code I am working with: 这是我正在使用的代码:
close all
clear all
clc
tic
file = 'ImageRegistrations.txt';
info = importdata(file);
ImageNames = info.textdata(:,1);
xoffset = info.data(:,1);
yoffset = info.data(:,2);
for i = 1:length(ImageNames);
ImageNames{i,1} = imread(ImageNames{i,1});
ImageNames{i,1} = flipud(ImageNames{i,1});
end
ImageNames = flipud(ImageNames);
for i=1:length(ImageNames)
diffx(i) = xoffset(length(ImageNames),1) - xoffset(i,1);
end
diffx = (diffx)';
diffx = flipud(diffx);
for j=1:length(ImageNames)
diffy(j) = yoffset(length(ImageNames),1) - yoffset(j,1);
end
diffy = (diffy)';
diffy = flipud(diffy);
matrix = zeros(max(diffy)+abs(min(diffy))+(2*1004),max(diffx)+abs(min(diffx))+(2*1002));
%matrix(1:size(ImageNames{1,1},1),1:size(ImageNames{1,1},2)) = ImageNames{1,1};
for q=1:length(ImageNames)
matrix((diffy(q)+abs(min(diffy))+1):(diffy(q)+abs(min(diffy))+size(ImageNames{q,1},1)),(diffx(q)+abs(min(diffx))+1):((diffx(q)+abs(min(diffx))+size(ImageNames{q,1},2)))) = ImageNames{q,1};
end
graymatrix = mat2gray(matrix);
graymatrix = flipud(graymatrix);
figure(2)
imshow(graymatrix)
imwrite(graymatrix, 'montage.tif')
toc
I use imwrite because it perserves the final montage in a full resolution file, whereas if I simply click save on the figure file it saves it as a low resolution file. 我使用imwrite是因为它可以将最终蒙太奇保留在完整分辨率的文件中,而如果我仅单击图形文件上的保存,则会将其保存为低分辨率文件。
thanks! 谢谢!
Error does what it says on the tin, really. 错误确实在锡纸上说了什么。 There is some sort of inbuilt limitation to input variable size in
imwrite
, and you're going over it. 在
imwrite
,输入变量的大小有某种内在的限制,您可以遍历它。
Note that most images are stored as uint8
but I would guess that you end up with doubles as a result of your processing. 请注意,大多数图像都以
uint8
形式存储,但是我想您会由于处理而最终加倍。 That increases the memory usage. 这增加了内存使用量。
It may be, therefore, that casting to another type would help. 因此,强制转换为另一种类型可能会有所帮助。 Try using
im2uint8
(presuming your variable graymatrix
is double, scaled between 0 and 1), before calling imwrite
. 在调用
imwrite
之前,尝试使用im2uint8
(假设变量graymatrix
是double,缩放范围为0到1)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.