Home > cellorganizer > utilities > img2xml.m

img2xml

PURPOSE ^

INDEX2XML Converts an indexed image to a sparse matrix, and saves as an xml

SYNOPSIS ^

function img2xml( img , filename )

DESCRIPTION ^

INDEX2XML Converts an indexed image to a sparse matrix, and saves as an xml
file

Input arguments    Description
img                image, represented as a matrix, to save as an xml
filename           Location to save .xml file to

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function img2xml( img , filename )
0002 %INDEX2XML Converts an indexed image to a sparse matrix, and saves as an xml
0003 %file
0004 %
0005 %Input arguments    Description
0006 %img                image, represented as a matrix, to save as an xml
0007 %filename           Location to save .xml file to
0008 
0009 % Author: Michelle Mackie (mmackie@andrew.cmu.edu)
0010 %
0011 % Copyright (C) 2012 Murphy Lab
0012 % Lane Center for Computational Biology
0013 % School of Computer Science
0014 % Carnegie Mellon University
0015 %
0016 % This program is free software; you can redistribute it and/or modify
0017 % it under the terms of the GNU General Public License as published
0018 % by the Free Software Foundation; either version 2 of the License,
0019 % or (at your option) any later version.
0020 %
0021 % This program is distributed in the hope that it will be useful, but
0022 % WITHOUT ANY WARRANTY; without even the implied warranty of
0023 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0024 % General Public License for more details.
0025 %
0026 % You should have received a copy of the GNU General Public License
0027 % along with this program; if not, write to the Free Software
0028 % Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
0029 % 02110-1301, USA.
0030 %
0031 % For additional information visit http://murphylab.web.cmu.edu or
0032 % send email to murphy@cmu.edu
0033 
0034 if( nargin > 2)
0035     error('CellOrganizer: Wrong number of input arguments.' );
0036 end
0037 
0038 if (length(size(img)) ~= 3)
0039    error('Invalid image' ); 
0040 end
0041 
0042 docNode = com.mathworks.xml.XMLUtils.createDocument('sparse');
0043 
0044 
0045 for z_index=1:size(img,3)
0046     z_slice = docNode.createElement('z-slice');
0047     img_slice = img(:,:,z_index);
0048     img_sparse = sparse(img_slice);
0049     [i,j,val] = find(img_sparse);
0050 
0051     for n=1:length(val)
0052        x = i(n);
0053        y = j(n);
0054        temp_val = val(n);
0055 
0056        sparse_element = docNode.createElement('element');
0057        x_node = docNode.createElement('x');
0058        x_text = docNode.createTextNode(num2str(x));
0059        x_node.appendChild(x_text);
0060        sparse_element.appendChild(x_node);
0061 
0062       y_node = docNode.createElement('y');
0063       y_text = docNode.createTextNode(num2str(y));
0064       y_node.appendChild(y_text);
0065       sparse_element.appendChild(y_node);
0066 
0067       val_node = docNode.createElement('value');
0068       val_text = docNode.createTextNode(num2str(temp_val));
0069       val_node.appendChild(val_text);
0070       sparse_element.appendChild(val_node);
0071       
0072       z_slice.appendChild(sparse_element);
0073       
0074     end
0075     docNode.getDocumentElement.appendChild(z_slice);
0076 end
0077 
0078 xmlwrite([filename '.xml'], docNode);
0079 end

Generated on Sun 29-Sep-2013 18:44:06 by m2html © 2005