Untitled

mail@pastecode.io avatar
unknown
matlab
7 months ago
703 B
1
Indexable
Never
clc
clear all;

a = imread('Lenna_(test_image).png');
subplot(1,3,1)
imshow(a);
title('Original Image');

w1 = 50;
w2 = 150;
r1 = 90;
r2 = 130;
L = 256;

alpha = w1/r1;
beta = (w2-w1)/(r2-r1);
gamma = ((L-1)-w2)/((L-1)-r2);

b = rgb2gray(a);
subplot(1,3,2)
imshow(b);
title('Gray Image');

[m,n] = size(b);
c=b;
for i=1:m
    for j=1:n
        r=b(i,j,:);
        if(r>0 & r<=r1)
            delta = alpha*r;
        elseif(r>=r1 & r<=r2)
            delta = beta*(r-r1)+w1;
        elseif(r>=r2 & r<=(L-1))
            delta = gamma*(r-r2)+w2;
        end
        c(i,j) = delta;
    end
end

subplot(1,3,3)
imshow(c);
title('Image after contrast streching');
Leave a Comment