pfsview.m (pfstools-2.1.0.tgz) | : | pfsview.m (pfstools-2.2.0.tgz) | ||
---|---|---|---|---|
skipping to change at line 17 | skipping to change at line 17 | |||
% channel - a real matrix, or a cell array of real matrixes. If the matrix | % 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 | % has the size(..,3)==3, it is recognized as an RGB color | |||
% image. | % image. | |||
% channel name - (optional) name for the channel given as next argument | % channel name - (optional) name for the channel given as next argument | |||
% after channel matrix. | % after channel matrix. | |||
% | % | |||
% See also: PFS_READ_IMAGE, PFS_WRITE_IMAGE, PFS_TRANSFORM_COLORSPACE. | % See also: PFS_READ_IMAGE, PFS_WRITE_IMAGE, PFS_TRANSFORM_COLORSPACE. | |||
% | % | |||
% Copyright 2009 Rafal Mantiuk | % Copyright 2009 Rafal Mantiuk | |||
width = -1; | width = -1; | |||
height = -1; | height = -1; | |||
title = 'matlab'; | title = 'matlab'; | |||
n = 1; | n = 1; | |||
for i=1:length( varargin ) | for i=1:length( varargin ) | |||
if iscell(varargin{i}) | ||||
C = varargin{i}; | if isa( varargin{i}, 'gpuArray' ) | |||
width = size( C{1}, 2 ); | img = gather( varargin{i} ); | |||
height = size( C{1}, 1 ); | else | |||
if( size( C, 1 ) > 1 ) | img = varargin{i}; | |||
for j=1:size(C,1) | end | |||
for k=1:size(C,2) | ||||
if( any( size(C{j,k}) ~= [height width] ) ) | if iscell(img) | |||
continue; % empty or invalid cell | C = img; | |||
end | width = size( C{1}, 2 ); | |||
ch_name = sprintf( 'c_%d_%dx%d', n, j, k ); | height = size( C{1}, 1 ); | |||
channels.(ch_name) = C{j, k}; | if( size( C, 1 ) > 1 ) | |||
end | for j=1:size(C,1) | |||
end | for k=1:size(C,2) | |||
else | if( any( size(C{j,k}) ~= [height width] ) ) | |||
for j=1:length(C) | continue; % empty or invalid cell | |||
ch_name = sprintf( 'cell_%d_%d', n, j ); | end | |||
channels.(ch_name) = C{j}; | ch_name = sprintf( 'c_%d_%dx%d', n, j, k ); | |||
end | channels.(ch_name) = C{j, k}; | |||
end | end | |||
n = n+1; | end | |||
elseif( isnumeric( varargin{i} ) ) | else | |||
m_size = size( varargin{i} ); | for j=1:length(C) | |||
width = m_size(2); | ch_name = sprintf( 'cell_%d_%d', n, j ); | |||
height = m_size(1); | channels.(ch_name) = C{j}; | |||
if( length(m_size) == 2 ) | end | |||
matrix_name = inputname( i ); | end | |||
if( isempty( matrix_name ) ) | n = n+1; | |||
ch_name = sprintf( 'matrix_%d', n ); | elseif( isnumeric( img ) ) | |||
else | m_size = size( img ); | |||
ch_name = matrix_name; | width = m_size(2); | |||
end | height = m_size(1); | |||
n = n+1; | if( length(m_size) == 2 ) | |||
channels.( ch_name ) = single( varargin{i} ); | matrix_name = inputname( i ); | |||
elseif( length(m_size) == 3 && m_size(3)==3 ) | if( isempty( matrix_name ) ) | |||
% Color channels | ch_name = sprintf( 'matrix_%d', n ); | |||
[channels.X channels.Y channels.Z] = pfs_transform_colorspace( 'RGB', | else | |||
single(varargin{i}), 'XYZ' ); | ch_name = matrix_name; | |||
elseif( length(m_size) == 3 && m_size(3)<10 ) | end | |||
matrix_name = inputname( i ); | n = n+1; | |||
if( isempty( matrix_name ) ) | channels.( ch_name ) = single( img ); | |||
ch_name = sprintf( 'matrix_%d', n ); | elseif( length(m_size) == 3 && m_size(3)==3 ) | |||
n = n+1; | % Color channels | |||
else | [channels.X channels.Y channels.Z] = pfs_transform_colorspace( 'RGB' | |||
ch_name = matrix_name; | , single(img), 'XYZ' ); | |||
end | elseif( length(m_size) == 3 && m_size(3)<10 ) | |||
for j=1:m_size(3) | matrix_name = inputname( i ); | |||
channels.( sprintf( '%s_%d', ch_name, j ) ) = single( varargin{i}( | if( isempty( matrix_name ) ) | |||
:,:,j) ); | ch_name = sprintf( 'matrix_%d', n ); | |||
end | n = n+1; | |||
else | else | |||
error( [ 'Cannot display matrix of the size [' num2str( m_size ) ']' ] | ch_name = matrix_name; | |||
); | end | |||
end | for j=1:m_size(3) | |||
elseif( islogical( varargin{i} ) ) | channels.( sprintf( '%s_%d', ch_name, j ) ) = single( img(:,:,j) | |||
ch_name = sprintf( 'bool_%d', n ); | ); | |||
n = n+1; | end | |||
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 | else | |||
channels.(varargin{i}) = channels.( ch_name ); | error( [ 'Cannot display matrix of the size [' num2str( m_size ) ']' | |||
channels = rmfield( channels, ch_name ); | ] ); | |||
clear ch_name; | end | |||
elseif( islogical( img ) ) | ||||
ch_name = sprintf( 'bool_%d', n ); | ||||
n = n+1; | ||||
channels.(ch_name) = double(img); | ||||
m_size = size( img ); | ||||
width = m_size(2); | ||||
height = m_size(1); | ||||
elseif( ischar( img ) ) | ||||
if( i == 1 ) | ||||
title = img; | ||||
else | ||||
if( ~exist( 'channels', 'var' ) || ~exist( 'ch_name', 'var' ) ) | ||||
error( 'channel_name argument must follow channel argument' ); | ||||
else | ||||
channels.(img) = channels.( ch_name ); | ||||
channels = rmfield( channels, ch_name ); | ||||
clear ch_name; | ||||
end | ||||
end | end | |||
end | ||||
end | end | |||
end | end | |||
% tmp file is used rather than pipes to run pfsview in background without | % tmp file is used rather than pipes to run pfsview in background without | |||
% blocking matlab | % blocking matlab | |||
tmp_file = tempname(); | tmp_file = tempname(); | |||
pfsout = pfsopen( tmp_file, height, width ); | pfsout = pfsopen( tmp_file, height, width ); | |||
pfsout.channels = channels; | pfsout.channels = channels; | |||
pfsout.tags.FILE_NAME = title; | pfsout.tags.FILE_NAME = title; | |||
pfsput( pfsout ); | pfsput( pfsout ); | |||
pfsclose( pfsout ); | pfsclose( pfsout ); | |||
tmp_file_path = pfs_fix_path( tmp_file ); % Fix paths on Windows | tmp_file_path = pfs_fix_path( tmp_file ); % Fix paths on Windows | |||
system( sprintf( '%s(pfsview <''%s'' && rm -f ''%s'') &%s', pfs_shell(), tmp_f ile_path, tmp_file_path, pfs_shell( 1 ) ) ); | system( sprintf( '%s(pfsview <''%s'' && rm -f ''%s'') &%s', pfs_shell(), tmp_fil e_path, tmp_file_path, pfs_shell( 1 ) ) ); | |||
end | end | |||
End of changes. 8 change blocks. | ||||
87 lines changed or deleted | 94 lines changed or added |