图像处理中的对比度拉伸变换 [英] Contrast stretching transformation in Image Processing
问题描述
我尝试使用Matlab查找问题的答案,但找不到.
I tried to find answer of question with using matlab but i couldn't find it.
我尝试使用此代码来解决问题.
I tried this code for solving of the question.
我的代码块:
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
我不知道如何找到这个问题的答案.如果您有帮助,我会很高兴.
I don't know how to find answer of this question. I will be glad if you help.
推荐答案
在这里,我将转换函数分为三个不同的区域,每个区域具有唯一的斜率.通过取相邻的x
值的差Run
和相邻的y
值的差Rise
来评估斜率.根据输入强度r
下降的位置进行if语句的过程将决定要使用的有效斜率.最后一步是添加每条线性线的偏移量.查找Effective_Run
是评估强度值下降到该区域有多远的过程.这可以通过用强度值减去区域的x
下限来完成.这将取决于要点.对于区域2,偏移量为s1 = 30
,对于区域3,偏移量为s2 = 230
.
Here I split the transform function into three distinct regions each with a unique slope. The slopes were evaluated by taking the difference in neighbouring x
values the Run
and the difference in neighbouring y
values the Rise
. The process of taking if statements depending on where the input intensity r
falls will dictate which effective slope to use. The last step is to add the offset of each linear line. Finding the Effective_Run
is a process of evaluating how far into the region the intensity value has fallen. This can be done by subtracting the x
lower bound of the region by the intensity value. This will be dependent on the points. For region 2 the offset is s1 = 30
and for region 3 the offset is s2 = 230
.
在方括号中,每个区域的边界可以描述为:
In bracket notation the bounds of each region can described as:
区域1:范围[0, r1]
Region 1: Range [0, r1]
区域2:范围(r1, r2)
Region 2: Range (r1, r2)
区域3:范围[r2, 255]
请花点时间查看逻辑和数学,以确保以下代码中没有错误:
Please take the time to look over the logic and mathematics to ensure no mistakes in the following code:
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进行运行
这篇关于图像处理中的对比度拉伸变换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!