Home > src > matlab > pfs_write_image.m

pfs_write_image

PURPOSE ^

PFS_WRITE_IMAGE write an RGB, luminance or multichannel image to a file.

SYNOPSIS ^

function pfs_write_image( file_name, img, options )

DESCRIPTION ^

PFS_WRITE_IMAGE write an RGB, luminance or multichannel image to a file.

 PFS_WRITE_IMAGE( file_name, IMG [, options] )

 Writes a luminance image if IMG is a 2D matrix, an RGB image if
 size(IMG,3) == 3, and a multi-channel image otherwise. Each channel in a
 multi-channel image has a name C1, C2, .., Cn. 

 'options' passes a string with additional options recognized by each of
 the image format writers. For example '--compression=PXR24' modifies the
 compression algorithm for OpenEXR files. See the manual pages of the
 "pfsout*" shell commands for the list of supported options. 

 The format of the file is recognized based in the file name extension:
 .hdr for Radiance images, .exr for OpenEXR, .jpg for JPEG and .png for
 PNG. See manual of "pfsout" shell command for the full list of the
 supported formats. 

 Currently only OpenEXR and PFS formats support multi-channel files. 

 Pass single precission matrices for better performance. 

 Example:
   pfs_write_image( 'image.exr', cat( 3, R, G, B ) );
 
   R, G, and B are 2D matrices with red, green and blue channel data.

 See also: PFS_WRITE_RGB, PFS_WRITE_LUMINANCE, PFS_WRITE_XYZ,
 PFS_READ_IMAGE, PFSVIEW.

 Copyright 2009 Rafal Mantiuk

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function pfs_write_image( file_name, img, options )
0002 %PFS_WRITE_IMAGE write an RGB, luminance or multichannel image to a file.
0003 %
0004 % PFS_WRITE_IMAGE( file_name, IMG [, options] )
0005 %
0006 % Writes a luminance image if IMG is a 2D matrix, an RGB image if
0007 % size(IMG,3) == 3, and a multi-channel image otherwise. Each channel in a
0008 % multi-channel image has a name C1, C2, .., Cn.
0009 %
0010 % 'options' passes a string with additional options recognized by each of
0011 % the image format writers. For example '--compression=PXR24' modifies the
0012 % compression algorithm for OpenEXR files. See the manual pages of the
0013 % "pfsout*" shell commands for the list of supported options.
0014 %
0015 % The format of the file is recognized based in the file name extension:
0016 % .hdr for Radiance images, .exr for OpenEXR, .jpg for JPEG and .png for
0017 % PNG. See manual of "pfsout" shell command for the full list of the
0018 % supported formats.
0019 %
0020 % Currently only OpenEXR and PFS formats support multi-channel files.
0021 %
0022 % Pass single precission matrices for better performance.
0023 %
0024 % Example:
0025 %   pfs_write_image( 'image.exr', cat( 3, R, G, B ) );
0026 %
0027 %   R, G, and B are 2D matrices with red, green and blue channel data.
0028 %
0029 % See also: PFS_WRITE_RGB, PFS_WRITE_LUMINANCE, PFS_WRITE_XYZ,
0030 % PFS_READ_IMAGE, PFSVIEW.
0031 %
0032 % Copyright 2009 Rafal Mantiuk
0033 
0034 img_sz = size( img );
0035 dims = length( img_sz );
0036 
0037 if( dims > 3 )
0038     error( 'image matrix has too many dimenstions' );
0039 end
0040 
0041 if( ~exist( 'options', 'var' ) )
0042     options = '';
0043 end
0044 
0045 fid = pfspopen( sprintf( '%spfsout ''%s'' %s%s', pfs_shell(), file_name, options, pfs_shell(1) ), 'w' );    
0046 pfs = pfsopen( fid, [img_sz(1) img_sz(2)] );
0047 
0048 if( dims == 2 || img_sz(3) == 1 )
0049     pfs.channels.Y = single(img);
0050 elseif( dims == 3 && img_sz(3) == 3 )
0051     [pfs.channels.X pfs.channels.Y pfs.channels.Z] = pfs_transform_colorspace( 'RGB', img, 'XYZ' );    
0052 else 
0053     for k=1:img_sz(3)
0054         pfs.channels.(sprintf('C%d', k)) = single(img(:,:,k));
0055     end
0056 end
0057 
0058 pfsput( pfs );
0059 pfsclose( pfs );
0060 pfspclose( fid );
0061 
0062 end

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