0001 function [varargout] = pfs_read_rgb( fileName )
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
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
0053 if ~ispc()
0054 pfspclose( fid );
0055 end
0056 end