Home > src > matlab > pfsview.m

pfsview

PURPOSE ^

PFSVIEW Shows set of matrices as images using pfsview

SYNOPSIS ^

function pfsview( varargin )

DESCRIPTION ^

PFSVIEW Shows set of matrices as images using pfsview

 PFSVIEW( ['title',] channel [,'channel name'], ... )

 title - (optional) a title to be displayed in the title bar of pfsview
 channel - a real matrix, or a cell array of real matrixes. If the matrix
           has the size(..,3)==3, it is recognized as an RGB color
           image.
 channel name - (optional) name for the channel given as next argument
           after channel matrix. 

 See also: PFS_READ_IMAGE, PFS_WRITE_IMAGE, PFS_TRANSFORM_COLORSPACE.

 Copyright 2009 Rafal Mantiuk

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function pfsview( varargin )
0002 %PFSVIEW Shows set of matrices as images using pfsview
0003 %
0004 % PFSVIEW( ['title',] channel [,'channel name'], ... )
0005 %
0006 % title - (optional) a title to be displayed in the title bar of pfsview
0007 % channel - a real matrix, or a cell array of real matrixes. If the matrix
0008 %           has the size(..,3)==3, it is recognized as an RGB color
0009 %           image.
0010 % channel name - (optional) name for the channel given as next argument
0011 %           after channel matrix.
0012 %
0013 % See also: PFS_READ_IMAGE, PFS_WRITE_IMAGE, PFS_TRANSFORM_COLORSPACE.
0014 %
0015 % Copyright 2009 Rafal Mantiuk
0016 
0017   width = -1;
0018   height = -1;
0019 
0020   title = 'matlab';
0021   n = 1;
0022   for i=1:length( varargin )
0023     if iscell(varargin{i})
0024       C = varargin{i};
0025       width = size( C{1}, 2 );
0026       height = size( C{1}, 1 );
0027       if( size( C, 1 ) > 1 )
0028           for j=1:size(C,1)
0029               for k=1:size(C,2)
0030                   if( any( size(C{j,k}) ~= [height width] ) )
0031                       continue; % empty or invalid cell
0032                   end
0033                   ch_name = sprintf( 'c_%d_%dx%d', n, j, k );
0034                   channels.(ch_name) = C{j, k};
0035               end              
0036           end
0037       else
0038           for j=1:length(C)
0039               ch_name = sprintf( 'cell_%d_%d', n, j );
0040               channels.(ch_name) = C{j};
0041           end
0042       end
0043       n = n+1;
0044     elseif( isnumeric( varargin{i} ) )
0045       m_size = size( varargin{i} );
0046       width = m_size(2);
0047       height = m_size(1);
0048       if( length(m_size) == 2 )
0049           matrix_name = inputname( i );
0050           if( isempty( matrix_name ) )
0051               ch_name = sprintf( 'matrix_%d', n );
0052           else
0053               ch_name = matrix_name;
0054           end
0055           n = n+1;
0056           channels.( ch_name ) = single( varargin{i} );
0057       elseif( length(m_size) == 3 && m_size(3)==3 )
0058           % Color channels
0059           [channels.X channels.Y channels.Z] = pfs_transform_colorspace( 'RGB', single(varargin{i}), 'XYZ' );
0060       else
0061           error( [ 'Cannot display matrix of the size [' num2str( m_size ) ']' ] );
0062       end
0063     elseif( islogical( varargin{i} ) )
0064       ch_name = sprintf( 'bool_%d', n );
0065       n = n+1;
0066       channels.(ch_name) = double(varargin{i});
0067       m_size = size( varargin{i} );
0068       width = m_size(2);
0069       height = m_size(1);
0070     elseif( ischar( varargin{i} ) )
0071       if( i == 1 )
0072         title = varargin{i};
0073       else
0074         if( ~exist( 'channels', 'var' ) || ~exist( 'ch_name', 'var' ) )
0075           error( 'channel_name argument must follow channel argument' );
0076         else 
0077           channels.(varargin{i}) = channels.( ch_name );
0078           channels = rmfield( channels, ch_name );
0079           clear ch_name;
0080         end
0081       end
0082     end
0083   end
0084 
0085   % tmp file is used rather than pipes to run pfsview in background without
0086   % blocking matlab
0087   tmp_file = tempname();
0088   pfsout = pfsopen( tmp_file, height, width );
0089   pfsout.channels = channels;
0090   pfsout.tags.FILE_NAME = title;
0091   pfsput( pfsout );  
0092   pfsclose( pfsout );
0093   
0094   system( sprintf( '%s(pfsview <''%s'' && rm -f %s) &%s', pfs_shell(), tmp_file, tmp_file, pfs_shell( 1 ) ) );
0095   
0096 end

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