如何在 MATLAB 中重新量化图像的动态范围?
我需要根据以下像素值转换统一重新量化图像的动态范围:
Pixel Value: Quantized Value
0 - 64 : 31
65 - 128 : 95
129 - 192 : 159
193 - 255 : 223
我想用量化值替换上述范围内的所有像素值。我如何在 MATLAB 中编写此代码?
I need to uniformly re-quantize the dynamic range of an image based on the following pixel value conversions:
Pixel Value: Quantized Value
0 - 64 : 31
65 - 128 : 95
129 - 192 : 159
193 - 255 : 223
I want to replace all the pixel values in the above ranges with the quantized values. How can I code this in MATLAB?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种方法是使用逻辑索引。给定一个图像矩阵
img
(可能是 2 -D 灰度或 3-D RGB),这将替换您的所有值:另一个选项是创建一个 256 元素查找表并使用图像中的值作为该表的索引:
请注意,这解决方案您必须注意图像矩阵的类别。许多图像属于
uint8
类,跨越值 0 到 255。要使用这些值作为索引,您必须将它们转换为可以存储更大整数的类(例如double
)以避免最大值 255 处的饱和,然后添加 1,因为您需要从 1 到 256 的索引。然后您需要将生成的图像矩阵转换回类uint8
。One way is to use logical indexing. Given a image matrix
img
(which could be 2-D grayscale or 3-D RGB), this will replace all your values:Another option is to create a 256-element look-up table and use the values in your image as indices into this table:
Note that with this solution you will have to be mindful of the class of your image matrix. Many images are of class
uint8
, spanning values 0 to 255. To use these values as an index you have to convert them to a class that can store larger integers (likedouble
) to avoid saturation at the maximum value of 255, then add one since you need an index from 1 to 256. You would then want to convert the resulting image matrix back to classuint8
.