Home > src > matlab > pfs_read_rgb.m

pfs_read_rgb

PURPOSE ^

PFS_READ_RGB Read image file and return R, G, and B color channels or a single 3D matrix.

SYNOPSIS ^

function [varargout] = pfs_read_rgb( fileName )

DESCRIPTION ^

PFS_READ_RGB Read image file and return R, G, and B color channels or a single 3D matrix.

 [R G B] = PFS_READ_RGB( file_name )
 IMG = PFS_READ_RGB( file_name)

 R, G, B - red, green and blue color channels, given as linear response
 img - 3D matrix image, where img(:,:,1:3) represents red, blue and green
       color channels

 PFS_READ_RGB accepts all formats recognized by the shell "pfsin"
 command.

 See also: PFS_READ_IMAGE, PFS_READ_LUMINANCE, PFS_READ_XYZ, PFS_WRITE_IMAGE.

 Copyright 2009 Rafal Mantiuk

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [varargout] = pfs_read_rgb( fileName )
0002 %PFS_READ_RGB Read image file and return R, G, and B color channels or a single 3D matrix.
0003 %
0004 % [R G B] = PFS_READ_RGB( file_name )
0005 % IMG = PFS_READ_RGB( file_name)
0006 %
0007 % R, G, B - red, green and blue color channels, given as linear response
0008 % img - 3D matrix image, where img(:,:,1:3) represents red, blue and green
0009 %       color channels
0010 %
0011 % PFS_READ_RGB accepts all formats recognized by the shell "pfsin"
0012 % command.
0013 %
0014 % See also: PFS_READ_IMAGE, PFS_READ_LUMINANCE, PFS_READ_XYZ, PFS_WRITE_IMAGE.
0015 %
0016 % Copyright 2009 Rafal Mantiuk
0017 
0018   %Check if file exists
0019   fid = fopen( fileName, 'rb' );
0020   if( fid == -1 ) 
0021     error( 'pfs_read_rgb: File "%s" does not exist', fileName );
0022   end
0023   fclose( fid );
0024 
0025   fid = pfspopen( sprintf( '%spfsin ''%s''%s', pfs_shell(), fileName, pfs_shell( 1 ) ), 'r' );
0026   pin = pfsopen( fid );
0027   pin = pfsget( pin );
0028 
0029   if( isfield( pin.channels, 'X' ) && isfield( pin.channels, 'Z' ) )
0030       [R G B] = pfs_transform_colorspace( 'XYZ', pin.channels.X, pin.channels.Y, pin.channels.Z, 'RGB' );
0031   elseif( isfield( pin.channels, 'Y' ) )
0032       R = pin.channels.Y;
0033       G = pin.channels.Y;
0034       B = pin.channels.Y;
0035   else
0036       error( 'Color channels missing in the pfs frame' );
0037   end
0038   
0039   if( nargout == 3 )
0040       varargout{1} = R;
0041       varargout{2} = G;
0042       varargout{3} = B;
0043   elseif( nargout  == 1 )
0044       varargout{1}(:,:,1) = R;
0045       varargout{1}(:,:,2) = G;
0046       varargout{1}(:,:,3) = B;
0047   else
0048       error( 'pfs_read_rgb: wrong number of output arguments' );
0049   end
0050   
0051   pfsclose( pin );
0052   % TODO: Check why crashes on windows
0053   if ~ispc()
0054       pfspclose( fid );
0055   end
0056 end

Generated on Tue 03-Mar-2009 13:03:09 by m2html © 2003