问题描述
|
我想知道是否有人建议使用支持[0,2 ^ 32]或更高范围内的整数值图像的图像格式,例如[0,2 ^ 64]。我对可能已经由MATLAB(&OpenCV,如果可能)支持的解决方案感兴趣,即具有库支持的图像格式以及在MATLAB和C / C ++(例如OpenCV)中对此类图像的读写访问权限。
我可以编写自己的读/写库,但我想避免重新发明轮子。如果不存在这样的库,那么我对将有助于实现此类图像的读/写库的通用格式感兴趣。
注意:我相信MATLAB对
.png
文件中的索引图像的支持仅限于[0,2 ^ 16]范围内的整数
谢谢
解决方法
您可以尝试TIFF。
MATLAB具有强大的界面:http://www.mathworks.com/help/techdoc/ref/tiffclass.html
例如,请看这里:http://www.mathworks.com/help/techdoc/import_export/f5-123068.html#br_c_iz-1
要么:
t = Tiff(\'uint32.tif\',\'w\');
imgdata=uint32(magic(10));
tagstruct.ImageLength = size(imgdata,1)
tagstruct.ImageWidth = size(imgdata,2)
tagstruct.Photometric = Tiff.Photometric.MinIsBlack
tagstruct.BitsPerSample = 32;
tagstruct.SampleFormat = Tiff.SampleFormat.UInt;
tagstruct.SamplesPerPixel = 1
tagstruct.RowsPerStrip = 16
tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky
tagstruct.Software = \'MATLAB\'
t.setTag(tagstruct)
t.write(imgdata);
t.close();
info = imfinfo(\'uint32.tif\');
data = imread(\'uint32.tif\');
class(data)
, 请注意,对于灰度图像,PNG图像的位深度最多为16。但是,您可能会偷偷摸摸地将32位或64位数据转换为一组红色,绿色,蓝色和alpha通道,然后将其另存为具有alpha透明度的truecolor RGB图像,这将为您提供4个通道(每通道16个)每个位总共可使用64位。
这里有几个例子...
在PNG文件中存储64位值:
该64位数字可以分为4个16位数字,并保存如下:
value = intmax(\'uint64\')-1; %# Sample 64-bit value
%# Writing the value to a file:
redChannel = uint16(bitshift(value,-48)); %# 16 bits for red
greenChannel = uint16(bitand(bitshift(value,-32),65535)); %# 16 bits for green
blueChannel = uint16(bitand(bitshift(value,-16),65535)); %# 16 bits for blue
alphaChannel = uint16(bitand(value,65535)); %# 16 bits for alpha
imageData = cat(3,redChannel,greenChannel,blueChannel); %# Concatenate color
%# channels to 3-D
imwrite(imageData,\'test.png\',\'Alpha\',alphaChannel); %# Create the file
%# Reading the value from the file:
[imageData,~,alphaChannel] = imread(\'test.png\'); %# Load the image data
result = bitshift(uint64(imageData(:,:,1)),48)+... %# Recover the 64-bit value
bitshift(uint64(imageData(:,2)),32)+...
bitshift(uint64(imageData(:,3)),16)+...
uint64(alphaChannel);
并且您应该看到原始的64位数字value
等于恢复的64位数字result
。
在PNG文件中存储32位数据:
32位数据可以分为4组8位数据,并保存如下:
data = [0 100 1000 2^32-1]; %# Sample vector of double values
data = uint32(data); %# Convert to unsigned 32-bit values
%# Writing the data to a file:
redChannel = uint8(bitshift(data,-24)); %# 8 bits for red
greenChannel = uint8(bitand(bitshift(data,255)); %# 8 bits for green
blueChannel = uint8(bitand(bitshift(data,-8),255)); %# 8 bits for blue
alphaChannel = uint8(bitand(data,255)); %# 8 bits for alpha
imageData = cat(3,blueChannel); %# Concatenate color
%# channels to 3-D
imwrite(imageData,alphaChannel); %# Create the file
%# Reading the data from the file:
[imageData,alphaChannel] = imread(\'test.png\'); %# Load the image data
result = bitshift(uint32(imageData(:,24)+... %# Recover the 32-bit values
bitshift(uint32(imageData(:,16)+...
bitshift(uint32(imageData(:,8)+...
uint32(alphaChannel);
并且data
和result
中的所有值都应该相等。
, 看看HDF5:https://hdfgroup.org/HDF5/
实际上,这是Matlab 7+存储Mat文件的格式,尽管Matlab完全放弃了HDF仅出于“性能原因”而仅存储行主要内容的严格定义,但这可能会有点问题。 Matlab还提供了与HDF5一起使用的高级和高级API,尽管如前所述有些奇怪。
您将能够使用任何所需的位深度和数字格式(也就是eeee 754单双精度)和通道而不受任何实际限制(默认情况下最多32个尺寸)。它还使您可以选择一些无损压缩详细信息,如果您要查看它们,它们将更适合您的单个问题-结果文件通常会更小。与tiff一样,您也可以在单个文件中存储多个图像(即数据集),HDFView允许以多种方式查看,包括各种调色板中的图像。
值得一提的每种语言/平台都具有对HDF5的绑定,因此可移植性也很好。