% UINT8_FunnyBiz
%
% Variables with type uint8 house integers between 0 and 255 and use one
% byte (8 bits) for the representation. 
%
% Commands of the type A = imread('MyPic.jpg') produce a uint8 array.
%
% If you intend to do image processing by working with A, you need to
% be aware of the subtleties associated with uint8 arithmetic.
%
clc

disp('>> a = uint8(250)'),       a = uint8(250)
disp('>> b = uint8(100)'),       b = uint8(100)

% Implications about the 0-to-255 range..

disp('>> c1 = a + 20'),          c1 = a + 20
disp('>> c2 = a - 300'),         c2 = a - 300
disp('>> c3 = a + b'),           c3 = a + b
disp('>> c4 = b - a '),          c4 = b - a
disp('>> c5 = uint8(300)'),      c5 = uint8(300)
disp('>> c6 = uint8(-10)'),      c6 = uint8(-10)

% Here is 3-by-3 uint8 array...
disp('>> C =  uint8([202  9  173 ; 245  217  193; 167  238  189])')
C =  uint8([202  9  173 ; 245  217  193; 167  238  189])

% Problem: Assume alfa is a uint8 variable. Assign to it the maximum
% discrepancy between C(2,2)  and its 8 neighbors. 

disp('>> M1 = C - C(2,2)')
M1 = C - C(2,2)
disp('>> alfa1 = uint8(max(max(abs(M1))))')
alfa1 = uint8(max(max(abs(M1))))

disp('>> M2 = double(C) - double(C(2,2))')
C =  uint8([202  9  173 ; 245  217  193; 167  238  189])
M2 = double(C) - double(C(2,2))
disp('>> alfa2 = uint8(max(max(abs(M2))))')
alfa2 = uint8(max(max(abs(M2))))

% Moral: Often it is better to convert a uint8 representation to a
% floating point representation using double().







