[英]What is the difference between a uint8 and a single image?
I already know uint8
contains intensity values between 0 and 255 (2 8 -1) and single contains values between 0 and 1, it is used to hold larger values without upsetting the range error. 我已经知道
uint8
包含0到255(2 8 -1)之间的强度值,single包含0到1之间的强度值,它用于保存较大的值而不会改变范围误差。 But, apart from that, are there any other differences? 但是,除此之外,还有其他区别吗?
What is the difference between imagesc((I/64)*64)
and imagesc((Is/64)*64)
, where I
is uint8
and Is
is single
? imagesc((I/64)*64)
和imagesc((Is/64)*64)
之间有什么区别,其中I
为uint8
, Is
为single
?
imagesc
just calls image
underneath. imagesc
只是在下面调用image
。 As for image
, it behaves a bit differently if integers or floats are supplied, as can be learned from image
's documentation: 对于
image
,如果提供整数或浮点数,则其行为会有所不同,可以从image
的文档中了解到:
If
C
is of type double , then an RGB triplet value of[0 0 0]
corresponds to black and[1 1 1]
corresponds to white.如果
C
为double类型,则[0 0 0]
的RGB三元组值对应于黑色,[1 1 1]
对应于白色。If
C
is an integer type, then the image uses the full range of data to determine the color.如果
C
是整数类型,则图像将使用整个数据范围来确定颜色。 For example, ifC
is of typeuint8
, then[0 0 0]
corresponds to black and[255 255 255]
corresponds to white.例如,如果
C
的类型为uint8
,则[0 0 0]
对应于黑色,[255 255 255]
对应于白色。 IfCData
is of typeint8
, then[-128 -128 -128]
corresponds to black and[127 127 127]
corresponds to white.如果
CData
的类型为int8
,则[-128 -128 -128]
对应于黑色,[127 127 127]
对应于白色。...
...
Converting Between Data Types
在数据类型之间转换
To convert indexed image data from an integer type to type
double
, add 1. For example, ifX8
is indexed image data of typeuint8
, convert it to typedouble
using:要将索引图像数据从整数类型转换为
double
类型,请添加1。例如,如果X8
是uint8
类型的索引图像数据,请使用以下命令将其转换为double
类型:X64 = double(X8) + 1;
To convert indexed image data from type
double
to an integer type, subtract 1 and useround
to ensure that all the values are integers.要将索引图像数据从
double
类型转换为整数类型,请减去1并使用round
来确保所有值都是整数。 For example, ifX64
is indexed image data of typedouble
, convert it touint8
using:例如,如果
X64
是double
类型的索引图像数据,请使用以下命令将其转换为uint8
:X8 = uint8(round(X64 - 1));
To convert true color image data from an integer type to type
double
, rescale the data.要将真彩色图像数据从整数类型转换为
double
类型,请重新缩放数据。 For example, ifRGB8
is true color image data of typeuint8
, convert it to double using:例如,如果
RGB8
是uint8
类型的真彩色图像数据,则使用以下命令将其转换为double:RGB64 = double(RGB8)/255;
To convert true color image data from type
double
to an integer type, rescale the data and useround
to ensure that all the values are integers.要将真彩色图像数据从
double
类型转换为整数类型,请重新缩放数据并使用round
确保所有值都是整数。 For example, ifRGB64
is image data of typedouble
, convert it touint8
using:例如,如果
RGB64
是double
类型的图像数据,则使用以下命令将其转换为uint8
:RGB8 = uint8(round(RGB64*255));
I = uint8(255*rand(1e3));
Is = single(I)/255;
tmpI = (I/64)*64;
tmpIs = (Is/64)*64;
% plot for prosterity
% figure;
% subplot(211)
% imagesc(tmpI)
% subplot(212)
% imagesc(tmpIs)
numel(unique(tmpI(:))) % gives 5
numel(unique(tmpIs(:))) % gives 256
Dividing an integer basically means binning of values, and then it stretches the data back to the original extend for plotting. 除以整数基本上意味着对值进行分箱,然后将数据拉伸回原始扩展以进行绘图。 In this case, you get
256/64 = 4
bins, with 0 as well, thus 5 possible values for your uint8
image. 在这种情况下,您将获得
256/64 = 4
bin,也为0,因此uint8
映像可能有5个值。 However, using single
you retain all unique numbers, since the precision is a lot higher. 但是,使用
single
会保留所有唯一数字,因为精度要高得多。
If you'd do the same test with a lot (order 2^52) elements in the rand
and use double
you'd see that that again has 2^32 times the number of unique elements of single
, just as uint16
will have 2^8 the number of unique elements of uint8
. 如果对
rand
的很多元素(阶数2 ^ 52)进行相同的测试并使用double
您会发现它再次具有single
唯一元素数的2 ^ 32倍,就像uint16
将具有2 ^ 8 uint8
的唯一元素的数量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.