matlab实现线性对比度展宽

clc;
clear all;
f=imread('1.bmp');
f=rgb2gray(f);
figure(1);
imshow(f);
[m,n]=size(f);
fa=40;
fb=120; 
ga=20;
gb=160; 
a=ga/fa; 
b=gb/fb;
b=(gb-ga)/(fb-fa);
c=(255-gb)/(255-fb);
for i=1:m
 for j=1:n
    if f(i,j)<fa
        g(i,j)=a*f(i,j); 
    elseif f(i,j)>=fa&f(i,j)<=fb
g(i,j)=b*(f(i,j)-fa)+ga;
     else
g(i,j)=c*(f(i,j)-fb)+gb;     
       end
     end
    end
figure(2);
imshow(g);

你可能感兴趣的:(matlab实现线性对比度展宽)