其中,Y 表示最终输出图像,而 X 表示输入图像。 该抛物线函数由三个系数 A、B 和 C 控制。?
上述公式中?
l =?输入图像的最小灰度值
h = 输入图像的最大灰度值
e = 输入图像的平均灰度值
L =?输出图像的最小值,通常为0
H =?输出图像的最大值,通常为255
E =?输出图像的平均值,自定义
?s =?输入图像的均方和
MATLAB参考代码
I = imread('pout.tif'); %READ THE INPUT IMAGE
figure,subplot(121), imshow(I);title('INPUT IMAGE');
x = double(I); % INPUT IMAGE
Lmin = min(x(:)); % MINIMUM OF INPUT IMAGE
Lmax = max(x(:)); % MAXIMUM OF INPUT IMAGE
Lmean = mean(x(:)); %MEAN OF INPUT IMAGE
LMssum = mean(x(:).^2); %MEAN SQUARE SUM OF INPUT IMAGE
Gmin = 0; %MINIMUM OF OUTPUT IMAGE
Gmax = 255; %MAXIMUM OF OUTPUT IMAGE
Gmean = 110; %MEAN OF OUTPUT IMAGE
bnum = Lmax.^2*(Gmean-Gmin) - LMssum*(Gmax-Gmin) + Lmin.^2*(Gmax-Gmean);
bden = 2*(Lmax*(Gmean-Gmin)-Lmean*(Gmax-Gmin)+Lmin*(Gmax-Gmean));
b = bnum/bden;
a = (Gmax-Gmin)/((Lmax-Lmin)*(Lmax+Lmin-2*b));
c = Gmin - a*(Lmin-b).^2;
y = a*(x-b).^2+c; %PARABOLIC FUNCTION
y = uint8(y);
subplot(122),imshow(y);title('OUTPUT IMAGE');
OpenCV参考代码
double Lmin, Lmax, Lmean, LMssum;
Cv2.MinMaxIdx(gray, out Lmin, out Lmax);
Lmean = (int)Cv2.Mean(gray);
LMssum = (int)Cv2.Mean(gray.Pow(2));
double Gmin = 0, Gmax = 255, Gmean = 110;
double bnum = Lmax * Lmax * (Gmean - Gmin) - LMssum * (Gmax - Gmin) + Lmin * Lmin * (Gmax - Gmean);
double bden = 2 * (Lmax * (Gmean - Gmin) - Lmean * (Gmax - Gmin) + Lmin * (Gmax - Gmean));
double b = bnum / bden;
double a = (Gmax - Gmin) / ((Lmax - Lmin) * (Lmax + Lmin - 2 * b));
double c = Gmin - a * (Lmin - b) * (Lmin - b);
for(int h=0; h< gray.Height; h++)
{
for (int w = 0; w < gray.Width; w++)
{
int v = gray.At<byte>(h, w);
double r = a * (v - b) * (v - b) + c;
gray.Set<byte>(h, w, (byte)r);
}
}