Error metrics how to calculate it, help me find bug in this code.
in
Programming Questions
•
10 months ago
Hello,
I would like to implement this formula in the program:
for two of the following images:
http://s13.postimage.org/yjeb8t6c7/strawberry.png
http://s15.postimage.org/eat6o24kb/strawberry_Red.png
This is my code:
I would like to implement this formula in the program:
for two of the following images:
http://s13.postimage.org/yjeb8t6c7/strawberry.png
http://s15.postimage.org/eat6o24kb/strawberry_Red.png
The result should be: 14298.064453125 and the result calculated by me in the program is: 132941.09947 ....
Can you give me some hints what I'm doing wrong? Thank you very much in advance!
Can you give me some hints what I'm doing wrong? Thank you very much in advance!
This is my code:
- //result must be: 14298,064453125
void setup()
{
background(200,200,200);
PImage img = loadImage("strawberry.bmp"); //picture original
PImage img1 = loadImage("strawberryRed.bmp"); // picture in Red channel
size(img.width*2,img.height);
image(img,0,0);
image(img1,img1.width,0);
functionErr(img, img1); //error function
}
void functionErr(PImage img, PImage img1) {
int N=img.width;
int M=img.height;
double sum=0;
float r,r1,r2=0;
float g,g1,g2=0;
float b,b1,b2=0;
for(int i=0; i<N; i++){
for(int j=0; j<M; j++){
color c = img.get(i,j); //color first picture pixel
color c1 = img1.get(i,j); // color second picture pixel
r=red(c);
g=green(c);
b=blue(c);
r1=red(c1);
g1=green(c1);
b1=blue(c1);
r2=r-r1; // difference color
g2=g-g1;
b2=b-b1;
float c2= r2+g2+b2;
sum+=pow(c2,2);
}
}
println(sum/(N*M));
}
1