Why do I get wrong results when I add two values inside a Matrix ?

4 views (last 30 days)
Hello everyone,
I am currently working on a matlab function that practically does the same thing as the demosaic function from the Matlab Image Toolbox. My function accepts an image file as input (which should already be treated by applying the bayer mask on it. I attached the used image as well) and returns the demosaic version of the image. I attached the source code file to this post.
I put a breakpoint on line 37 after the M Matrix is calculated and found out that the following line
mid = (M(1,1)+M(1,3)+M(3,1)+M(3,3))/4;
does not calculate the right values for the (2,2) value of the Matrix.
Here is a capture of a simple test I did manually on the debugger on the same line.
Am I doing something wrong with this code?

Accepted Answer

Matt J
Matt J on 7 Nov 2014
Convert M to double or single type first
M=double(M);

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!