MATLAB: If the result of subtraction of two values in a image matrix is negative, the value is set to zero.

image analysisimage processing

Hi, Im new to image processing in matlab. c is a matrix containing 60 images and the following is the piece of my code:
i=c{1}(2,1); % value of 2nd row 1st column of 1st image(c{1}) matrix
j=c{1}(2,2); % value of 2nd row 2nd column of 1st image(c{1}) matrix
k=i-j;
l=j-i;
output:
i=4
j=9
k=0
l=5
Problem:
As you can see from out put the negative value is set to zero i.e k=0.
I want the negative value i.e the actual value of k (-5) should be displayed instead of zero.

Best Answer

Very likely your image values are in 'uint8' format, and this is how matlab does its subtraction in that format. To do otherwise, first convert the arrays to 'double' format:
k = double(i)-double(j);