Discussions on Lab 7 goes here.
error diffusion makes image brighter --karl.ostmo.1, Wed, 19 Mar 2008 15:03:39 -0400 reply
I'm pretty sure I followed the error diffusion algorithm and equations given in the lab to the letter, but my image comes out a lot brighter than the original. The error-diffused result looks pretty nice (I would say better than the ordered dithering result), but I did a quick average of the pixel brightness: sum(sum(X))/prod(size(X)), and the original image is ~108.5 while my error-diffused image is ~164.9. Any thoughts?
error diffusion makes image brighter --karl.ostmo.1, Wed, 19 Mar 2008 16:30:26 -0400 reply
I found out what the problem was: imread('house.tif') produces a matrix of uint8 type. This can cause problems when you are distributing the error, if your arithmetic is done in a certain way. MATLAB has counterintuitive behavior when dealing with "int" types. Observe the following MATLAB command sequence:
>> double(1.0/2.0) * 1 ans =
0.5000
>> double(1.0/2.0) * uint8(1) ans =
1
Recall that in C, if any term in the expression is a "float" type, the float type dominates the expression, such that ((int) 1)/((float) 2) produces the correct answer of 0.5. However, it appears that in MATLAB, the "uint8" type dominates if it is found anywhere in the expression, which leads to uint8(1)/double(2) producing 1. MATLAB also "rounds" integer division instead of performing the "floor" function::
>> double(1.0/3.0) * uint8(1) ans =
0
>> double(2.0/3.0) * uint8(1) ans =
1