理论部分来自《全景图像拼接关键技术研究》,这里讲了一个全局调整光照亮度的办法,很简单易懂:
%AA、BB是两幅原图 左 右
%A、B是重叠区域对应在两幅图的位置 A is the left and B is the right.
%转换了颜色空间
%下面是根据《全景图像拼接关键技术研究》中的亮度调整办法
AA=imread('F:\fisheye\others1.jpg');
BB=imread('F:\fisheye\others2.jpg');
[H,W,k]=size(AA);
rdata1=-76;
L=W+1+rdata1;
R=W;
n=R-L+1;
for i=1:H
for j=L:R
jj=j-L+1;
A(i,jj,1)=AA(i,j,1);
A(i,jj,2)=AA(i,j,2);
A(i,jj,3)=AA(i,j,3);
B(i,jj,1)=BB(i,jj,1);
B(i,jj,2)=BB(i,jj,2);
B(i,jj,3)=BB(i,jj,3);
end
end
A=uint8(A);
B=uint8(B);
%上面是根据之前H矩阵找到的两幅图的重叠部分A、B
[mb,nb,kb]=size(B);
I2=zeros(mb,nb);
v2=0;
for i=1:mb
for j=1:nb
I2(i,j)=0.59*B(i,j,1)+0.11*B(i,j,2)+0.3*B(i,j,3);
v2=v2+I2(i,j);
end
end
[ma,na,ka]=size(A);
I1=zeros(ma,na);
v1=0;
for i=1:ma
for j=1:na
I1(i,j)=0.59*A(i,j,1)+0.11*A(i,j,2)+0.3*A(i,j,3);
v1=v1+I1(i,j);
end
end
k=v1/v2;
[m,n,kk]=size(BB);
for i=1:m
for j=1:n
BB(i,j,1)=k*BB(i,j,1);
BB(i,j,2)=k*BB(i,j,2);
BB(i,j,3)=k*BB(i,j,3);
end
end
结果:
前两幅是原图 曝光差异大 后面这幅是对第二幅图调整亮度的结果图 这样就行了 效果还不错!
即:
Mat rejust_light(Mat waittoberejustimg, Mat destinateimg){
Mat waittoberejustgrayimg(waittoberejustimg.size(), CV_8UC1, Scalar(0));
cvtColor(waittoberejustimg, waittoberejustgrayimg, CV_RGB2GRAY);
Mat destinategrayimg(destinateimg.size(), CV_8UC1, Scalar(0));
cvtColor(destinateimg, destinategrayimg, CV_BGR2GRAY);
int waitimgsum = 0, destinateimgsum = 0;
for (int i = 0; i < waittoberejustgrayimg.rows;i++)
{
uchar* data = waittoberejustgrayimg.ptr(i);
for (int j = 0; j < waittoberejustgrayimg.cols;j++)
{
waitimgsum += (int)data[j];
}
}
for (int i = 0; i < destinategrayimg.rows; i++)
{
uchar* data = destinategrayimg.ptr(i);
for (int j = 0; j < destinategrayimg.cols; j++)
{
destinateimgsum += (int)data[j];
}
}
float ratio = (float)destinateimgsum / waitimgsum;
for (int i = 0; i < waittoberejustimg.rows; i++)
{
for (int j = 0; j < waittoberejustimg.cols * 3; j++)
{
waittoberejustimg.ptr(i)[j] = ratio*waittoberejustimg.ptr(i)[j];
}
}
return waittoberejustimg;
}
---------------------
原文:https://blog.csdn.net/wd1603926823/article/details/49849317