图1 图2 光影
通过运算将光影从图1中去掉
实现步骤:
1.对图像2作平滑去噪声处理 。方法:周围25个像素去平均,得到SP2;
2.得到SP2中R、G、B各个分量的最大值得到MaxR,MaxG,MaxB;
3.对图1(P1)的每一个像素:
P1.r=P1.r/SP2.r*MaxR
P1.g=P1.g/SP2.g*MaxG
P1.b=P1.b/SP2.b*MaxB
代码片断:
class ClassLensComp{
private:
DataProcess * dpRGB;// = new DataProcess();
DataProcess * dpsMSK;
pixel Smooth(pixel *, size_t, size_t);
public:
//pixel GetV1(int, int);
ClassLensComp(DataProcess *, DataProcess *);
void LensComp(DataProcess* );
};
/////////////////////////////////////////////////////////////
其中DataProcess 是pixel结构的数组
struct pixel
{
double r;
double g;
double b;
}
/////////////////////////////////////////////////////////////
ClassLensComp::ClassLensComp(DataProcess* RGB_In, DataProcess* sMSK_In)
{
dpRGB=RGB_In;
dpsMSK=sMSK_In;
}
void ClassLensComp::LensComp(DataProcess* OutPut)
{
size_t i,j;
pixel *RGBBuf=dpRGB->get_rgbdata();
pixel *sMSKBuf=dpsMSK->get_rgbdata();
pixel *OutPutBuf=OutPut->get_rgbdata();
size_t W=dpRGB->get_rgb_width(); //the sMSK width is the same as the GRB's
size_t H=dpRGB->get_rgb_height(); //the sMSK height is the same as the GRB's
pixel MaxsMSK(0,0,0); //Save the max r,g,b
pixel* sMSKBuffer=new pixel[H*W];
//for(k=0;k<3;k++)
{
//smoothed sMSK;
for(i=0;i<H;i++)
for (j=0;j<W;j++)
{
//ignore the two circles pixels of the picture.
//if pixel is in this bound, copy from original
if ((i<=1) || (i>=H-2) || (j<=1) || (i>=W-2) )
sMSKBuffer[i*W+j]=sMSKBuf[i*W+j];
else
sMSKBuffer[i*W+j]=Smooth(sMSKBuf,i,j);
}// The sMSK has been smoothed first
//get MAXrgb
for(j=0;j<W*H;j++)
{
if (MaxsMSK.r<sMSKBuffer[j].r)
MaxsMSK.r =sMSKBuffer[j].r;
if (MaxsMSK.g<sMSKBuffer[j].g)
MaxsMSK.g =sMSKBuffer[j].g;
if (MaxsMSK.b<sMSKBuffer[j].b)
MaxsMSK.b =sMSKBuffer[j].b;
}
//
for(i=0;i<H;i++)
for (j=0;j<W;j++)
{
OutPutBuf[i*W+j].r =RGBBuf[i*W+j].r/sMSKBuffer[i*W+j].r * MaxsMSK.r ;
OutPutBuf[i*W+j].g =RGBBuf[i*W+j].g/sMSKBuffer[i*W+j].g * MaxsMSK.g ;
OutPutBuf[i*W+j].b =RGBBuf[i*W+j].b/sMSKBuffer[i*W+j].b * MaxsMSK.b ;
}
}
delete[] sMSKBuffer;
}
///////////////////////////////////////////////////////////////////////////////
pixel ClassLensComp::Smooth(pixel* RGBBuf, size_t x, size_t y)
{
size_t i,j;
size_t W=dpRGB->get_rgb_width(); //the sMSK width is the same as the GRB's
pixel sum=(0,0,0);
for(i=x-2;i<=x+2;i++)
for (j=y-2;j<=y+2;j++)
{
sum.r =sum.r +RGBBuf[i*W+j].r ;
sum.g =sum.g +RGBBuf[i*W+j].g ;
sum.b =sum.b +RGBBuf[i*W+j].b ;
}
sum.r=sum.r/25;
sum.g=sum.g/25;
sum.b=sum.b/25;
return sum;
}
///////////////////////////////////////////////////////////////////////////////
结果图片
结果图片有点过亮, 再校正一下即可