Hi.
I am trying to implement adding then subtracting images but I can't seem to get it right. My thoughts are to load the image. add the pixel values. Firstly, I can get the pixel location but I DON'T KNOW HOW TO DISPLAY THE PIXEL VALUES from the pixel location.
Secondly, I generate a new blank image using the cvCreateImage opencv function. But I don't know how to get the pixel values from the pixel location, add the pixel values together then put it in the blank image I created. I can't use the cvAdd or any opencv functions. Similarly, the same issues apply for the subtraction of the images. Please help.
using namespace std;
typedef unsigned char uchar;
int main (int argc, char *argv[])
{
// Declare the variables
IplImage *image, *img;
int height, width;
int i, j;
uchar** ImageData;
uchar* data, data2;
double mean, std_dev;
CvScalar sc, s;
cvNamedWindow("Ass1", 1);
img = cvLoadImage(argv[1],1);
//convert to greyscale image
image = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 1);
cvCvtColor(img, image,CV_BGR2GRAY);
cvShowImage("Ass1", image);
cvWaitKey(0);
//Calculate the height and width of the image
height = image->height;
width = image->width;
data = (uchar *)image->imageData;
//Add the pixels together
IplImage *add;
add = cvCreateImage( cvGetSize(img), IPL_DEPTH_8U, 1 );
//data2 = (uchar*)add->imageData;
//cvGetRawData(add, (uchar**)&data2);
double maxi = 255;
for (int x = 0; x < height; x++)
{
for (int y = 0; y < width; y++)
{
data[((height * y) + x)] = data[((height * y) + x)] + data[((height * y) + x)];
if (data[((height * y) + x)] < maxi)
data[((height * y) + x)] = maxi;
}
}
cvReleaseImage(&image);
cvDestroyWindow("Ass1");
return 0;
}