图像标准化的需求是什么? [英] What is the need of normalisation in image?

查看:119
本文介绍了图像标准化的需求是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网上看到了这段代码

I saw this code in the internet

imgN = double(img-min(img(:)))/(max(img(:)-min(img(:))));

将图像标准化为0..1。它的意义是什么?它也显示此错误

to normalize the image in 0..1 . What's the meaning of it? Also its shows this error

Error using  / 
Integers can only be combined with integers of the same class, or scalar doubles.


推荐答案

在MATLAB中,许多函数都假设有关图像中的值。通常,图像存储为 uint8 double 。在 uint8 的情况下,范围是 0 ... 255 (这是<$中的所有可能值C $ C> UINT8 )。对于 double ,MATLAB选择的值范围为 0 ... 1 。要正确使用 imshow imwrite 等功能,您的 double 图像必须正确缩放,否则某些像素无法正确显示。

In MATLAB, many functions make assumptions about the range of values in an image. Usually, images are stored either as uint8 or double. In the case of uint8, the range is 0...255 (which is all possible values in a uint8.). For double, MATLAB chose a value range from 0...1. To use functions like imshow, imwrite and others correctly, your double image has to be scaled correctly, otherwise some pixels are not displayed correctly.

代码中有一个小错误:它基本上是一个分区 a / b ,其中 a double(img - min(img(:))) b (max(img(:)) - min(img(:)))。如果输入图像的类型为 double ,则可以正常工作。但是,如果它是 uint8 或任何其他类型,则分子 a 将转换为 double ,而分母 b 保留例如 UINT8 。您将有一个部门 double / uint8 。 MATLAB在错误消息中告诉您,它不能在分区中混合类型。一个简单的解决方案是将分母 b 转换为 double

There is a small bug in the code: It is basically a division a / b, where a is double(img - min(img(:))) and b is (max(img(:)) - min(img(:))). If your input image is of type double, this will work fine. However if it is uint8 or any other type, the numerator a will be converted to double, while the denominator b stays e.g. uint8. You will have a division double / uint8. MATLAB tells you in the error message, that it can not mix types in division. An easy solution is to also convert the denominator b to double:

imgN = double(img-min(img(:))) / double(max(img(:)-min(img(:))));

这篇关于图像标准化的需求是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆