Page 148 - Computational Colour Science Using MATLAB
P. 148

IMPLEMENTATIONS AND EXAMPLES                      135

                % polynomial transforms obtained from getlincam
                % caldata is a 3 by 4 matrix produced from getlincam.m
                % RGB is an n by 3 matrix of RGB values (in range 0-255)


                RGB = RGB/255;
                imsize = size(RGB);
                RGB = reshape(RGB, prod(imsize)/3, 3);

                for i=1:3
                  x = polyval(caldata(i,:),RGB(:,i));
                  RGB(:,i) = x*255;
                end

                RGB(RGB0) = 0;
                RGB(RGB255) = 255;

                RGBout = reshape(RGB,imsize);





               The format for lincam is

                  [tRGB] = lincam(CALDATA,RGB)

             where CALDATA is a 364 matrix obtained from getlincam and RGB is an
             m6n63 matrix of camera RGB values where the image size is m6n. The output
             of the function is an m6n63 matrix of linearized camera RGB values. Unlike
             many of the functions in the earlier part of this book, this function operates on
             the whole image with a single function call. In this respect the MATLAB
             function reshape is extremely useful.
               An image may be read into MATLAB using the simple instruction

                  image = imread(‘test.tif’);

             where test.tif is the name of the image file. For an RGB image of size
             1276101, for example, the variable image would now be defined by

                  image   127610163      38481 uint8 array

             It is necessary to use the double command, thus

                  image = double(image);

             in order to convert the variable image from UINT format to DOUBLE format.
   143   144   145   146   147   148   149   150   151   152   153