Matlab如何用imwrite函數寫UINT16的圖像 || Matlab報錯:UINT16圖像數據需要特定設置爲12或16的位深

1. 在Matlab命令窗口輸入命令:

help imwrite

會有如下解釋:

If the input array is of class uint16 and the format supports 16-bit data (JPEG, PNG, and TIFF), imwrite outputs the data as 16-bit values. If the format does not support 16-bit values, imwrite issues an error. Several formats, such as JPEG and PNG, support a parameter that lets you specify the bitdepth of the output data.

If the input array is of class double, and the image is a grayscale or RGB color image, imwrite assumes the dynamic range is [0,1] and automatically scales the data by 255 before writing it to the file as 8-bit values.

2. 如果你要保存成uint16的灰度圖像的矩陣數據是非uint16的類型:

則必須先將double類型轉換爲uint16的類型,執行命令:

data11=uint16(data1);

結果如下:

3. 然後執行命令:

imwrite(data11,'image.png','png','bitdepth',16);

最終得到uint16的灰度圖像image.png。如下圖所示:

參考網址:https://wenda.so.com/q/1534806305217644

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章