【问题标题】:Contrast stretching transformation in Image Processing图像处理中的对比度拉伸变换
【发布时间】:2021-02-25 00:07:36
【问题描述】:

Graph and Question

我尝试使用 matlab 找到问题的答案,但找不到。

我尝试使用此代码来解决问题。

我的代码块:

p1=[0,0];
p2=[75,5];
p3=[140,250];
p4=[255,255];
m1=(p1(1,2)-p2(1,2))/(p1(1,1)-p2(1,1));
m2=(p2(1,2)-p3(1,2))/(p2(1,1)-p3(1,1));
m3=(p3(1,2)-p4(1,2))/(p3(1,1)-p4(1,1));
c1=p1(1,2)-m1*p1(1,1);
c2=p2(1,2)-m2*p2(1,1);
c3=p3(1,2)-m3*p3(1,1);
% Transformation function
t=[];
for x=0:255
if(x<=p2(1,1))
t=[t (m1*x+c1)];
end
if(x>p2(1,1) && x<=p3(1,1))
t=[t (m2*x+c2)];
end
if(x>p3(1,1) && x<=p4(1,1))
t=[t (m3*x+c3)];
end
end
for n=1:s(1,1)
for m=1:s(1,2)
ot(n,m)=t(a(n,m)+1);
end
end

我不知道如何找到这个问题的答案。如果您能提供帮助,我会很高兴。

【问题讨论】:

  • 获得更多问题答案的小技巧是解释您在代码块中采用的方法/尝试。

标签: matlab image-processing signal-processing


【解决方案1】:

在这里,我将变换函数分成三个不同的区域,每个区域都有一个独特的斜率。通过取相邻x 值的差异Run 和相邻y 值的差异Rise 来评估斜率。根据输入强度r 下降的位置,采用 if 语句的过程将决定使用哪个有效斜率。最后一步是添加每条直线的偏移量。查找Effective_Run 是评估强度值下降到该区域多远的过程。这可以通过用强度值减去区域的x 下限来完成。这将取决于点。对于区域 2,偏移量是 s1 = 30,对于区域 3,偏移量是 s2 = 230

在括号表示法中,每个区域的边界可以描述为:

区域 1:范围 [0, r1]

区域 2:范围 (r1, r2)

区域 3:范围 [r2, 255]

请花时间检查逻辑和数学,以确保以下代码中没有错误:


r = input("Please input the intensity value, r: "); 
fprintf("\n");

r1 = 70;
r2 = 150;
s1 = 30;
s2 = 230;

Point_1 = [0 0];
Point_2 = [r1 s1];
Point_3 = [r2 s2];
Point_4 = [255 255];

x = 1;
y = 2;

%Slope of region 1%
Rise = Point_2(y) - Point_1(y);
Run = Point_2(x) - Point_1(x);
Slope_1 = Rise/Run;

%Slope of region 2%
Rise = Point_3(y) - Point_2(y);
Run = Point_3(x) - Point_2(x);
Slope_2 = Rise/Run;

%Slope of region 3%
Rise = Point_4(y) - Point_3(y);
Run  = Point_4(x) - Point_3(x);
Slope_3 = Rise/Run;

if r <= r1
fprintf("Region 1\n"); 
s = Slope_1*r;
fprintf("The output intensity, s = T(r) is: %.2f\n",s); 

elseif (r1 < r) && (r < r2)
fprintf("Region 2\n"); 
Constant_Offset = s1;
Relative_Run = (r - r1);
s = Slope_2*Relative_Run + Constant_Offset;
fprintf("The output intensity, s = T(r) is: %.2f\n",s); 

elseif r >= r2
fprintf("Region 3\n"); 
Constant_Offset = s2;
Relative_Run = (r - r2);
s = Slope_3*Relative_Run + Constant_Offset;
fprintf("The output intensity, s = T(r) is: %.2f\n",s); 
   
end

使用 MATLAB R2019b 运行

【讨论】:

  • 先生,非常感谢。我还有最后一个问题,如果你能看到我会很高兴。
  • @Deeper Blue 好的,我去看看。
  • 最后一个问题非常不同。我找到了一些答案,但可能都是错误的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-02-28
  • 1970-01-01
  • 1970-01-01
  • 2017-07-04
  • 1970-01-01
  • 1970-01-01
  • 2017-02-25
相关资源
最近更新 更多