Hi everybody, I would like to blend pictures manually using a loop. In detail I want to copy the white pixels from a binary image (0==black, 255==white, not other values possible) to a new Picture which is at the beginning a Mat just including black pixels.
My code works fine if I use a Mat created with white pixels. But if I use my binary images I load into OpenCV I get artefacts. I cannot understand why this is happening. If I look in the source image in OpenCV the pixels have just 0 or 255, but if I vary with the thresholdvalue I get different Artefacts.
Normaly intensity >=1 should work well, but If I use for example 100 I get still differend artefacts.
This is the code I use:
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace std;
using namespace cv;
void Vblend(Mat src, Mat blend)
{ int colu, row;
int intensity;
for (row=0; row<=480; row++)
{
for (colu=0; colu<=640; colu++)
{
intensity = src.at<uchar>(row, colu);
if(intensity >=1) {blend.at<uchar>(row, colu)=255;}
}
}
}
int main()
{
Mat src= imread("pic.jpg",CV_LOAD_IMAGE_GRAYSCALE);
Mat blend(480,640,CV_8UC1,Scalar(0));
namedWindow("src");
namedWindow("blend");
Vblend(src,blend);
imshow("src", src);
imshow("blend",blend);
while(char(waitKey(1)) != 'q') {}
return 0;
}
In this picture you can see the original on the left and the artefacts on the right.
How can I eliminate the artefacts?
Thank you very much for your help :-)