I want to count only the vignette area of this image , like i have the image here
How I can count or iterate/pass through only in the area where vignette is applied and leave the other area ? I only want to apply the algorithm on the area where vignette is applied , I tried it like give scalar to red color and extract area where it found the red color but its not working like not giving the results because color become lighter when coming towards centre of the image.
The vignette darkens the corners and edges by multiplying the image intensity with the following mask:
This is the original image here
I want to blending overlay
the **only vignette part of** vignette image
with the original image
Here is my code for blending overlay
void blending_overlay(Mat& img1 , Mat& img2 , Mat& out)
{
Mat result(img1.size(), CV_32FC3);
for(int i = 0; i < img1.size().height; ++i){
for(int j = 0; j < img1.size().width; ++j){
for (int c=0 ; c<img1.channels();c++){
float target = (float)img1.at<uchar>(i, 3*j+c)/255. ;
float blend = (float)img2.at<uchar>(i, 3*j+c)/255. ;
if(target > 0.5){
result.at<float>(i, 3*j+c) = ((1 - (1-2*(target-0.5)) * (1-blend)));
}
else{
result.at<float>(i, 3*j+c) = ((2*target) * blend);
}
}
}
}
result.convertTo(out,CV_8UC3,255);
}
int main( int argc, char** argv )
{
Mat Img1=imread("D:\\Vig.png",-1); // the vignete in the question
Mat Img2=imread("D:\\i.png"); // the iamge in the question
cv::resize(Img1,Img1,Img2.size());
Img1.convertTo(Img1,CV_32FC4,1.0/255.0);
Img2.convertTo(Img2,CV_32FC3,1.0/255.0);
vector<Mat> ch;
split(Img1,ch);
Mat mask = ch[3].clone(); // here's the vignette
ch.resize(3);
Mat I1,I2,result;
cv::multiply(mask,ch[0],ch[0]);
cv::multiply(mask,ch[1],ch[1]);
cv::multiply(mask,ch[2],ch[2]);
merge(ch,I1);
vector<Mat> ch2(3);
split(Img2, ch2);
cv::multiply(1.0-mask,ch2[0],ch2[0]);
cv::multiply(1.0-mask,ch2[1],ch2[1]);
cv::multiply(1.0-mask,ch2[2],ch2[2]);
merge(ch2,I2);
I1.convertTo(I1,CV_8UC3,255);
I2.convertTo(I2,CV_8UC3,255);
result=I1+I2; // The image with the vignette in the question
result.convertTo(result,CV_8UC4,255);
Mat result2;
Mat mask2;
Mat image = imread ("D:\\i.png"); // image in the question
blending_overlay(image,result,result2,mask2);
imshow("Image",result2);
waitKey(0);
}
It works for blending vignette image with the original image but I only want to blend the vignette part from vignette image with the original image
The result i am getting is this