Code covered by the BSD License  

Highlights from
Statistical Learning Toolbox

from Statistical Learning Toolbox by Dahua Lin
Functions for statistical learning, pattern recognition and computer vision, covering many topics.

Description of slimg2mat
Home > sltoolbox > utils > slimg2mat.m

slimg2mat

PURPOSE ^

SLIMG2MAT Converts an image array to a double matrix

SYNOPSIS ^

function M = slimg2mat(img)

DESCRIPTION ^

SLIMG2MAT Converts an image array to a double matrix

 $ Syntax $
   - M = slimg2mat(img)

 % Arguments $
   - img:      the image
   - M:        the converted matrix

 $ Description $
   - M = slimg2mat(img) converts a variety of image arrays to a double
     2D matrix. In detail, the RGB image will be turned to a grayscale 
     image, in addition, the value of uint8 or other integer types will
     be converted to double value with range [0, 1] by im2double.

 $ History $
   - Created by Dahua Lin, on Jul 25th, 2006

CROSS-REFERENCE INFORMATION ^

This function calls:
This function is called by:
  • slimgsetprep SLIMGSETPREP organizes the images in a MATLAB friendly way

SOURCE CODE ^

0001 function M = slimg2mat(img)
0002 %SLIMG2MAT Converts an image array to a double matrix
0003 %
0004 % $ Syntax $
0005 %   - M = slimg2mat(img)
0006 %
0007 % % Arguments $
0008 %   - img:      the image
0009 %   - M:        the converted matrix
0010 %
0011 % $ Description $
0012 %   - M = slimg2mat(img) converts a variety of image arrays to a double
0013 %     2D matrix. In detail, the RGB image will be turned to a grayscale
0014 %     image, in addition, the value of uint8 or other integer types will
0015 %     be converted to double value with range [0, 1] by im2double.
0016 %
0017 % $ History $
0018 %   - Created by Dahua Lin, on Jul 25th, 2006
0019 %
0020 
0021 
0022 % color processing
0023 d = ndims(img);
0024 n = size(img, 3);
0025 if d > 3 || n == 2 || n > 3
0026     error('sltoolbox:invalidimg', ...
0027         'The image should be 1-channel gray image or 2-channel RGB image');
0028 end
0029 if n == 3
0030     img = rgb2gray(img);
0031 end
0032 
0033 % type conversion
0034 if isa(img, 'double')
0035     M = img;
0036 else
0037     M = im2double(img);
0038 end
0039 
0040 
0041

Generated on Wed 20-Sep-2006 12:43:11 by m2html © 2003

Contact us at files@mathworks.com