MATLAB: Contrast stretching transformation in Image Processing

contrast enhancementimage processingImage Processing Toolboxlinear interpolation

I tried to solve for question but i didn't do.
I tried this code for solving.
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.

Best Answer

Wow. Try this much easier way:
r = [70, 150]
s = [30, 230];
output = interp1(r, s, 110) % output is 130.