写一个uint16图像 [英] Write a uint16 image
问题描述
如何在MATLAB中将数据类型 uint16
的图像写入文件?我尝试使用以下命令写入文件,但它给了我一个错误
How can I write an image of datatype uint16
to a file in MATLAB? I try to write to the file using the following command, but it gives me an error
imwrite(pimg, 'h44', 'jpg')
使用writejpg时出错> set_jpeg_props(第183行)< br>
UINT16图像数据需要bitdepth专门设置为
12或16.
writejpg中的错误(第49行)
props = set_jpeg_props(data, varargin {:});
imwrite中的错误(第472行)
feval(fmt_s.write,data,map,filename,
paramPairs {:}); < br>
image16bit错误(第666行)
imwrite(imgnew1,'h44','jpg');
Error using writejpg>set_jpeg_props (line 183)
UINT16 image data requires bitdepth specifically set to either 12 or 16.
Error in writejpg (line 49)
props = set_jpeg_props(data,varargin{:});
Error in imwrite (line 472)
feval(fmt_s.write, data, map, filename, paramPairs{:});
Error in image16bit (line 666)
imwrite(imgnew1,'h44','jpg' );
推荐答案
保存超过8位的JPEG图像时,必须指定 BitDepth
选项:
You must specify the BitDepth
option when saving JPEG images with more than 8-bits:
% note that 16-bit only accepts grayscale images
img = imread('peppers.png');
imwrite(im2uint16(img), '12bit.jpg', 'BitDepth',12);
imwrite(rgb2gray(im2uint16(img)), '16bit.jpg', 'BitDepth',16);
不幸的是,没有多少程序支持12位/ 16位JPEG图像,所以你可能会无法在外部打开它。您可以使用JPEG2000格式:
Unfortunately, not many programs have support for 12-bit/16-bit JPEG images, so you might not be able to open it externally. You could use the JPEG2000 format instead:
imwrite(im2uint16(img), 'out.jp2');
这篇关于写一个uint16图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!