简体   繁体   English

使用MATLAB以全分辨率将许多图像的蒙太奇图像保存为一个大图像文件

[英]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.

相关问题 MATLAB:更改2个图像的蒙太奇方向 - MATLAB: changing montage orientation of 2 images Matplotlib:如何以全分辨率保存图像? - Matplotlib: How to save an image at full resolution? 将多个 TextView 保存为大分辨率图像 - Save multiple TextViews as image of large resolution 使用Imagemagick压缩非常高分辨率的图像文件 - compress very large resolution image file using Imagemagick 在Python中以全分辨率显示和保存大型2D矩阵 - Display and Save Large 2D Matrix with Full Resolution in Python 将图像合并到一个文件中,而无需在内存中创建完整图像 - Merge images into one file without creating the full image in memory 如何使用imwrite在matlab中保存多张图像? - how to save more than one image in matlab using imwrite? MatLab(图像处理,图像采集)如何在不覆盖原始文件名的情况下通过网络摄像头保存捕获的图像? - MatLab (Image Processing, Image Acquisition) How to save captured images by webcam without overwriting the original file name? 如何平均一组图像并将平均图像保存为使用MATLAB的平均图像 - How to average a set of images and save the averaged image as the averaged image using MATLAB 在Matlab中获取图像分辨率 - Getting image resolution in matlab
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM