Home > cellorganizer > utilities > tif2img.m

tif2img

PURPOSE ^

TIF2IMG Reads a multichannel tif and loads the image to workspace.

SYNOPSIS ^

function img = tif2img( filename )

DESCRIPTION ^

TIF2IMG Reads a multichannel tif and loads the image to workspace.

 Inputs:
 filename = string containing path to image file. files may be of any BioFormats supported type.

 Outputs:
 img = resulting image matrix

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function img = tif2img( filename )
0002 %TIF2IMG Reads a multichannel tif and loads the image to workspace.
0003 %
0004 % Inputs:
0005 % filename = string containing path to image file. files may be of any BioFormats supported type.
0006 %
0007 % Outputs:
0008 % img = resulting image matrix
0009 
0010 % Author: Ivan E. Cao-Berg (icaoberg@cmu.edu)
0011 % Created: August 5, 2008
0012 %
0013 % Copyright (C) 2008-2012 Murphy Lab
0014 % Carnegie Mellon University
0015 %
0016 % April 11, 2012 I. Cao-Berg Removed contrast stretch of the image
0017 % June 25, 2012 I. Cao-Berg Updated code so that the Matlab array
0018 %               inherits the properties of the tiff, i.e. the
0019 %               bit-depth
0020 %
0021 %
0022 % This program is free software; you can redistribute it and/or modify
0023 % it under the terms of the GNU General Public License as published
0024 % by the Free Software Foundation; either version 2 of the License,
0025 % or (at your option) any later version.
0026 %
0027 % This program is distributed in the hope that it will be useful, but
0028 % WITHOUT ANY WARRANTY; without even the implied warranty of
0029 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0030 % General Public License for more details.
0031 %
0032 % You should have received a copy of the GNU General Public License
0033 % along with this program; if not, write to the Free Software
0034 % Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
0035 % 02110-1301, USA.
0036 %
0037 % For additional information visit http://murphylab.web.cmu.edu or
0038 % send email to murphy@cmu.edu
0039 
0040 if nargin ~= 1
0041     error('CellOrganizer: Wrong number of input arguments');
0042 else%loads a multichannel tif to workspace
0043     
0044     img=[];
0045     if ~isstr(filename)
0046         disp('CellOrganizer: filename has to be a string');
0047         return;
0048     end
0049     if ~(exist(filename)==2)
0050         disp('CellOrganizer:filename does not exist');
0051         return;
0052     end
0053      %get information about this image
0054     info = imfinfo( filename );
0055     %recurse and load every channel to the workspace
0056     for i=1:1:size( info, 1 )
0057         %icaoberg june 25, 2012 by passing the image info
0058         %the method imread inherits the properties of the original file
0059         %most importantly the bit depth
0060         %img(:,:,i) = imread( filename, i ); %#ok<AGROW>
0061         img(:,:,i) = imread( filename, i, 'Info', info ); %#ok<AGROW>
0062     end
0063     
0064     %icaoberg june 25, 2012
0065     %don't make the assumption images are uint8
0066     %img = uint8( img );
0067     %contrast-stretch the image
0068     %img = ml_bcimg( img, [], [0 255] );
0069 end
0070 end%tif2img

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