[英]Convert indexed image colormap to uint8
I'm trying to read colormap of an image using this code: 我正在尝试使用以下代码读取图像的颜色图:
[X, map] = imread('D:\Eye.png');
But map
is rescaled to [0,1]
type double
. 但是
map
被重新缩放为[0,1]
类型double
。 How can I get the colormap in uint8
range [0,255]
? 如何获得
uint8
范围[0,255]
的颜色图?
This can be solved by simply rescaling map
and casting it to uint8
: 这可以通过简单地缩放
map
并将其转换为uint8
来解决:
uint8(255*map);
Optionally, you can round it before casting (the default rounding scheme, as above, is floor
): (可选)您可以在投射前对其进行四舍五入(如上所述,默认的四舍五入方案为
floor
):
uint8(round(255*map));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.