Logo Search packages:      
Sourcecode: pfstools version File versions  Download package

pfsview.m

function pfsview( varargin )
% Shows set of high-dynamic range matrices using pfsview
%
% Usage: 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 [height width 3], it is recognized as an RGB color
%           image.
% channel name - (optional) name for the channel given as next argument

  width = -1;
  height = -1;

  title = 'matlab';
  n = 1;
  for i=1:length( varargin )
    if iscell(varargin{i})
      C = varargin{i};
      width = size( C{1}, 2 );
      height = size( C{1}, 1 );
      if( size( C, 1 ) > 1 )
          for j=1:size(C,1)
              for k=1:size(C,2)
                  if( any( size(C{j,k}) ~= [height width] ) )
                      continue; % empty or invalid cell
                  end
                  ch_name = sprintf( 'c_%d_%dx%d', n, j, k );
                  channels.(ch_name) = C{j, k};
              end              
          end
      else
          for j=1:length(C)
              ch_name = sprintf( 'cell_%d_%d', n, j );
              channels.(ch_name) = C{j};
          end
      end
      n = n+1;
    elseif( isnumeric( varargin{i} ) )
      m_size = size( varargin{i} );
      width = m_size(2);
      height = m_size(1);
      if( length(m_size) == 2 )
          ch_name = sprintf( 'matrix_%d', n );
          n = n+1;
          channels.( ch_name ) = varargin{i};
      elseif( length(m_size) == 3 && m_size(3)==3 )
          % Color channels
          [channels.X channels.Y channels.Z] = pfs_transform_colorspace( 'RGB', varargin{i}, 'XYZ' );
      else
          error( [ 'Cannot display matrix of the size [' num2str( m_size ) ']' ] );
      end
    elseif( islogical( varargin{i} ) )
      ch_name = sprintf( 'bool_%d', n );
      n = n+1;
      channels.(ch_name) = double(varargin{i});
      m_size = size( varargin{i} );
      width = m_size(2);
      height = m_size(1);
    elseif( ischar( varargin{i} ) )
      if( i == 1 )
        title = varargin{i};
      else
        if( ~exist( 'channels', 'var' ) || ~exist( 'ch_name', 'var' ) )
          error( 'channel_name argument must follow channel argument' );
        else 
          channels.(varargin{i}) = channels.( ch_name );
          channels = rmfield( channels, ch_name );
          clear ch_name;
        end
      end
    end
  end

  % tmp file is used rather than pipes to run pfsview in background without
  % blocking matlab
  tmp_file = tempname();
  pfsout = pfsopen( tmp_file, height, width );
  pfsout.channels = channels;
  pfsout.tags.FILE_NAME = title;
  pfsput( pfsout );  
  pfsclose( pfsout );
  
  system( sprintf( '%s(pfsview <''%s'' && rm -f %s) &%s', pfs_shell(), tmp_file, tmp_file, pfs_shell( 1 ) ) );
  
end

Generated by  Doxygen 1.6.0   Back to index