4.5.5 Image Manipulation


RGB Image Matrix

While a matrix contains information on how many rows and columns to display, it is internally stored as a linear array. This fact can be used to copy data from a matrix to a worksheet column as in this instance where we

  1. Import an image file
  2. Extract the Red, Green and Blue (RGB) channels (matrix to matrix)
  3. Copy the channel data (matrix to column)
  4. Construct a string representation of the RGB values
// Point to a sample image and import
fname$ = SYSTEM.PATH.PROGRAM$ + "Samples\Image Processing and Analysis\Flower.jpg";
impImage;
// Split the RGB into separate Red, Green and Blue matrices
imgRGBsplit r:=[RGBOUT]RED!1 g:=[RGBOUT]GREEN!1 b:=[RGBOUT]BLUE!1;
// Create a new Workbook
newbook;
wks.ncols = 4;
wks.col1.lname$ = Red;
wks.col2.lname$ = Green;
wks.col3.lname$ = Blue;
wks.col4.lname$ = RGB;
// Worksheet ranges
range raDR = 1, raDG = 2, raDB = 3;
// Matrix ranges
range raR = [RGBOUT]RED!1;
range raG = [RGBOUT]GREEN!1;
range raB = [RGBOUT]BLUE!1;
// Copy data from Matrix to Workbook by range assignment
raDR = raR;
raDG = raG;
raDB = raB;
// Create a string showing the RGB triplet
col(D) = col(1)$ + " " + col(2)$ + " " + col(3)$;