# Different output in adding two images. Hi, I am using OpenCV 4.0.0 with C++. I have few doubts. I need explanation for output of addition : When I am adding two images A and B of same size : 1) (A+B)/2 and 2) (A/2)+(B/2) the output is same while when I am making one image 3) C = (A+B) and in next line C=C/2 the output is different. I was expecting 1) (A+B)/2 and 3) C = (A+B) and in next line C=C/2 to have same output but this was not same and rather 1) and 2) were giving same output. Note : All the images are of type CV_8UC1. Please give proper explanation.

edit retag close merge delete

## Comments

not sure but it seems like some decimal point issue here. For example: A=133 B=51 A/2= 133/2=67 ( no decimal points are allowed ) B/2 =51/2=26 A/2+B/2=93, but (A+B)/2=92

Initially I also thought that but the difference is not 1 unit it is more like the value A=230 B = 240 so A/2 = 115 and B/2 = 120 so (A/2+B/2) = 235. But (A+B) = 255 since it is uint8 (max value 255) and (A+B)/2 = 127. I was expecting this value but it is coming as 235. When I am adding (A+B) in one line and storing it in another image C and in next line dividing C/2 I am getting 127. That is what making me confused.