That's because j
is an image that is most likely belonging to a data type that is unsigned. This means negative values are not supported and get truncated to zero. If you desire negative number support, cast the variable to a supported type that can handle this... such as double
, or perhaps int8
. However, I'm assuming you'll want to use this for floating point applications, so double
should be fine:
function complexity2imgloop_90(filename)
j=imread(filename);
j = double(j); %// Change here
m=max(j(:));
x=m-1;
u=-x;
....
Minor Note
Using i
and j
as variables is very bad practice. Those are reserved for the complex variable i = sqrt(-1);, j = sqrt(-1);
. Shadowing i
or j
is not recommended because it makes it more difficult to create complex numbers. You would essentially have to type in sqrt(-1)
to facilitate the same behaviour. There are also other disadvantages to doing this.
Take a look at this Stack Overflow post by Shai Bagon for more details: Using i and j as variables in Matlab