Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 如何创建一个包含传递函数的查找表,以便在给定的量内增加/减少图像的亮度_Matlab - Fatal编程技术网

Matlab 如何创建一个包含传递函数的查找表,以便在给定的量内增加/减少图像的亮度

Matlab 如何创建一个包含传递函数的查找表,以便在给定的量内增加/减少图像的亮度,matlab,Matlab,我试图创建一个函数,返回一个查找表,其中包含用于增加/减少亮度的传递函数,如下所示 if inputvalue < -c outputvalue = 0 else if inputvalue > 255 - c outputvalue = 255 else outputvalue = inputvalue + c 如果不使用if和else,则解决方案更简单: 从标称LUT0:255开始 将c添加到标称LUT 使用min和max 注意:在MATLAB中,您不

我试图创建一个函数,返回一个查找表,其中包含用于增加/减少亮度的传递函数,如下所示

if inputvalue < -c
    outputvalue = 0
else if inputvalue > 255 - c
    outputvalue = 255
else
    outputvalue = inputvalue + c

如果不使用
if
else
,则解决方案更简单:

  • 从标称LUT
    0:255
    开始
  • c
    添加到标称LUT
  • 使用
    min
    max

    注意:在MATLAB中,您不需要将范围限制为[0255],因为
    uint8(Lut)
    隐式地执行此操作
代码如下:

function Lut = brightnessLUT(c)
    Lut = (0:255) + c;
    % Note: In MATLAB you don't need to limit the range to [0, 255], because uint8(Lut) does it implicitly.  
    Lut = max(min(Lut, 255), 0); %Limit Lut to range [0, 255].
    Lut = uint8(Lut);
end
通常,使用
min
max
进行阈值化是一种很好的做法


我添加了阈值代码,因为我假设您将使用它作为在其他编程语言中实现的准备(或者只是为了学习如何一般地构建LUT)

为什么不直接使用
Iout=uint8(Iin+c)
?请注意,如果c<-c为正值
c
,则始终为false;如果为负值
c
,则始终为true!如果强制转换到
uint8
,则到
[0255]
范围的夹紧是隐式的,不需要显式添加<代码>Lut=uint8((0:255)+c)可以。@CrisLuengo,当然…,我添加了阈值代码,只是为了演示如何在一般情况下构建LUT(无论如何都不需要构建LUT)。我在帖子中添加了评论。当然,直截了当是件好事。这是个好答案。为了完整起见,我只想把这个评论留在这里。
function Iout = enhanceBrightness(Iin,c)
Lut = brightnessLUT(c);
Iout = intlut(Iin,Lut);
end
function Lut = brightnessLUT(c)
    Lut = (0:255) + c;
    % Note: In MATLAB you don't need to limit the range to [0, 255], because uint8(Lut) does it implicitly.  
    Lut = max(min(Lut, 255), 0); %Limit Lut to range [0, 255].
    Lut = uint8(Lut);
end