Dav*_*man 3 lookup matlab image image-processing contrast
我正在尝试进行一些图像处理,我给它一个8位灰度图像.我应该通过生成一个查找表来改变图像的对比度,该查找表可以增加50到205之间像素值的对比度.我使用以下MATLAB代码生成了一个查找表.
a = 2;
x = 0:255;
lut = 255 ./ (1+exp(-a*(x-127)/32));
Run Code Online (Sandbox Code Playgroud)
当我绘图时lut,我得到如下图:

到目前为止这么好,但我如何提高50到205之间像素值的对比度?变换映射的最终图应该类似于:

从你的评论来看,你只需要一个线性地图,其中强度被< 50映射到0,强度被> 205映射到255,其他一切都是两者之间的线性映射.你可以这样做:
slope = 255 / (205 - 50); % // Generate equation of the line -
% // y = mx + b - Solve for m
intercept = -50*slope; %// Solve for b --> b = y - m*x, y = 0, x = 50
LUT = uint8(slope*(0:255) + intercept); %// Generate points
LUT(1:51) = 0; %// Anything < intensity 50 set to 0
LUT(206:end) = 255; %// Anything > intensity 205 set to 255
Run Code Online (Sandbox Code Playgroud)
LUT现在看起来像:
plot(0:255, LUT);
axis tight;
grid;
Run Code Online (Sandbox Code Playgroud)

注意我是如何截断的强度时,他们< 50和> 205.MATLAB在索引1处开始索引,因此我们需要将强度偏移1,以便它们正确映射到从0开始的像素强度.
要最终将其应用于您的图像,您所要做的就是:
out = LUT(img + 1);
Run Code Online (Sandbox Code Playgroud)
这是假设这img是您的输入图像.再次注意,我们必须通过+1MATLAB在位置1开始索引来抵消输入,而强度从0开始.
您可以通过使用轻松完成此操作imadjust,这基本上可以为您提供此功能.你这样称呼它:
outAdjust = imadjust(in, [low_in; high_in], [low_out; high_out]);
Run Code Online (Sandbox Code Playgroud)
low_in并high_in表示图像中存在的最小和最大输入强度.请注意,它们之间是标准化的[0,1]. low_out并high_out调整图像的强度,以便low_in映射到low_out,high_in映射到high_out,以及其他所有内容之间的对比度.对于你的情况,你会这样做:
outAdjust = imadjust(img, [0; 1], [50/255; 205/255]);
Run Code Online (Sandbox Code Playgroud)
这应该拉伸对比度,使得输入强度50映射到输出强度0,输入强度205映射到输出强度255.任何强度< 50和> 205得到自动饱和,以0和255分别.
| 归档时间: |
|
| 查看次数: |
2118 次 |
| 最近记录: |