简体   繁体   English

如何更改图像的像素值范围?

[英]How can I change the pixel value range in an image?

I have grayscale images with values in the range [0-65533]. 我有灰度图像,其值在[0-65533]范围内。 I've never see this before. 我以前从未见过。 What is this range? 这个范围是多少?

I want to scale the values to the range [0-1200]. 我想将值缩放到[0-1200]范围。 I tried the imadjust function but it does not work because this function required values between 0.0 and 1.0 only. 我尝试了imadjust函数,但由于该函数仅需要0.0到1.0之间的值,所以它不起作用。

How can I use imadjust to scale these values properly? 如何使用不imadjust来正确缩放这些值?

That range of values suggest that your grayscale image contains unsigned 16-bit integers, ie it is of type uint16 (integer values from 0 to 65535). 该值范围表明您的灰度图像包含无符号的16位整数,即它的类型为uint16 (从0到65535的整数值)。 The documentation for imadjust states that it supports images of this type, but it's still a little tricky to get the results you want. imadjust的文档指出它支持这种类型的图像,但是要获得所需的结果仍然有些棘手。

Regardless of the image type, the contrast limits are always expected to be in the range [0 1] . 不论图像类型如何,对比度极限始终期望在[0 1]范围内。 This will require you to rescale them yourself by dividing by 65535 : 这将需要您自己除以65535来重新缩放它们:

scaledImage = imadjust(uint16(inputImage), [0 65533]./65535, [0 1200]./65535);

Note that I also added the conversion uint16(...) just to make absolutely sure the input image is that type when passed to imadjust . 请注意,我还添加了转换uint16(...)只是为了确保输入图像在传递给imadjust时就是该类型。 If your input image happened to be converted to type double first, imadjust would expect the values to be in the range [0 1] for the image as well, which would give you an incorrect output in this case. 如果您输入的图像碰巧先转换为double类型, imadjust会期望该值也位于该图像的[0 1]范围内,在这种情况下会给您带来不正确的输出。

如果我理解正确,则可以执行以下操作:

newimage=1200.*oldimage./65533;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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