简体   繁体   English

uint8和单个图像有什么区别?

[英]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)之间有什么区别,其中Iuint8Issingle

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. 如果Cdouble类型,则[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, if C is of type uint8 , then [0 0 0] corresponds to black and [255 255 255] corresponds to white. 例如,如果C的类型为uint8 ,则[0 0 0]对应于黑色, [255 255 255]对应于白色。 If CData is of type int8 , 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, if X8 is indexed image data of type uint8 , convert it to type double using: 要将索引图像数据从整数类型转换为double类型,请添加1。例如,如果X8uint8类型的索引图像数据,请使用以下命令将其转换为double类型:

 X64 = double(X8) + 1; 

To convert indexed image data from type double to an integer type, subtract 1 and use round to ensure that all the values are integers. 要将索引图像数据从double类型转换为整数类型,请减去1并使用round来确保所有值都是整数。 For example, if X64 is indexed image data of type double , convert it to uint8 using: 例如,如果X64double类型的索引图像数据,请使用以下命令将其转换为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, if RGB8 is true color image data of type uint8 , convert it to double using: 例如,如果RGB8uint8类型的真彩色图像数据,则使用以下命令将其转换为double:

 RGB64 = double(RGB8)/255; 

To convert true color image data from type double to an integer type, rescale the data and use round to ensure that all the values are integers. 要将真彩色图像数据从double类型转换为整数类型,请重新缩放数据并使用round确保所有值都是整数。 For example, if RGB64 is image data of type double , convert it to uint8 using: 例如,如果RGB64double类型的图像数据,则使用以下命令将其转换为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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM