Question

Contrast Stretching: Write your own program to implement a piecewise linear transformation for contrast adjustment using MATL

Output intensity Level s ( ) r2, S2 (r1, ) r Input Intensity Level Fig. 1. Ilustration of a piecewise linear transformation f

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please upvote if you like the answer, as it helps the community a lot.

Also if you have any doubts, feel free to ask in comments, we will reach you ASAP.

(image.png)

We will apply contrast stretching on above image.

3) SOLUTION: (contrast_stretch.m)

clear all;
close all;
clc;

%% Reading an image
a=imread('image.png');
a=double(a);
s=size(a);

%% Defining points and calculating equation parameters
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


%% Getting output image
for n=1:s(1,1)
for m=1:s(1,2)
ot(n,m)=t(a(n,m)+1);
end
end

plot(t)
grid on;
xlabel('Intensity in input image');
ylabel('Intensity in output image')
title('Piece-wise linear transformation : Contrast stretching function')


figure()
subplot(1,2,1)
imshow(a/255)
title('Original image')
subplot(1,2,2)
imshow(ot./255)   
title('Contrast stretching')

1) & 2) OUTPUT:

Figure 1 Figure 2 g z+ Z- -f* Insert Text Axes Grid Autoscale z+ z, t. Insert Text Axes Grid Autoscale Piece-wise linear tran

We have stretched the range from 75-140 to 5-250. This makes it clearer and the differences more visible to naked eyes.

Add a comment
Know the answer?
Add Answer to:
Contrast Stretching: Write your own program to implement a piecewise linear transformation for contrast adjustment using...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT