00001 //# ImageUtilities.h: Some utility functions handy for accessing images 00002 //# Copyright (C) 1996,1997,1999,2000,2001,2002 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be addressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 //# 00027 //# $Id$ 00028 #ifndef IMAGES_IMAGEUTILITIES_H 00029 #define IMAGES_IMAGEUTILITIES_H 00030 00031 00032 #include <casacore/casa/aips.h> 00033 #include <casacore/scimath/Mathematics/GaussianBeam.h> 00034 #include <casacore/lattices/Lattices/TiledShape.h> 00035 #include <casacore/casa/Utilities/PtrHolder.h> 00036 #include <casacore/casa/Utilities/CountedPtr.h> 00037 00038 namespace casacore { //# NAMESPACE CASACORE - BEGIN 00039 00040 //# Forward Declarations 00041 template <class T> class ImageInterface; 00042 template <class T> class Vector; 00043 template <class T> class Quantum; 00044 template <class T> class MaskedArray; 00045 template <class T> class PtrHolder; 00046 class CoordinateSystem; 00047 class Coordinate; 00048 class String; 00049 class IPosition; 00050 class LogIO; 00051 class AxesSpecifier; 00052 class ImageAttrHandler; 00053 00054 // 00055 // <summary> 00056 // Utility functions for Image manipulation 00057 // </summary> 00058 // 00059 // 00060 // <use visibility=export> 00061 // 00062 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos=""> 00063 // </reviewed> 00064 // 00065 // <prerequisite> 00066 // <li> IPosition 00067 // <li> Arrays 00068 // <li> Lattice 00069 // </prerequisite> 00070 // 00071 // <synopsis> 00072 // Some helpful static functions that are common to some of my image 00073 // analysis application classes. 00074 // </synopsis> 00075 // 00076 // <motivation> 00077 // I needed some bits and pieces. My goal isto move this rag-tag bunch 00078 // out of here into other classes as time goes on. So far 00079 // I have eliminated 80% of the original ! 00080 // </motivation> 00081 // 00082 // <todo asof="1996/11/27"> 00083 // <li> 00084 // </todo> 00085 00086 00087 class ImageUtilities 00088 { 00089 public: 00090 // Open disk image (can be any registered image). Exception 00091 // if fileName empty or file does not exist or file is not 00092 // of legal image type. For Casacore images, the default mask is 00093 // applied. 00094 // <group> 00095 template<class T> 00096 static void openImage (PtrHolder<ImageInterface<T> >& image, 00097 const String& fileName); 00098 00099 template<class T> 00100 static void openImage (ImageInterface<T>*& image, 00101 const String& fileName); 00102 00103 template<class T> 00104 static SHARED_PTR<ImageInterface<T> > openImage (const String& fileName); 00105 // </group> 00106 00107 // Copy MiscInfo, ImageInfo, brightness unit and logger (history) from in to out 00108 template <typename T, typename U> 00109 static void copyMiscellaneous (ImageInterface<T>& out, 00110 const ImageInterface<U>& in, 00111 Bool copyImageInfo = True); 00112 00113 // Copy a mask from one image to another 00114 template <typename T, typename U> 00115 static void copyMask (ImageInterface<T>& out, 00116 const ImageInterface<U>& in, 00117 const String& maskOut, const String& maskIn, 00118 AxesSpecifier axesSpecifier); 00119 00120 // Copy the attributes from one image to another. 00121 static void copyAttributes (ImageAttrHandler& out, 00122 ImageAttrHandler& in); 00123 00124 // Add one degenerate axis for each of the specified coordinate types. 00125 // If the outfile string is given the new image is a PagedImage. 00126 // If the outfile string is empty, the new image is a TempImage. 00127 template <typename T> 00128 static void addDegenerateAxes ( 00129 LogIO& os, 00130 PtrHolder<ImageInterface<T> >& outImage, 00131 const ImageInterface<T>& inImage, 00132 const String& outFile, Bool direction, 00133 Bool spectral, const String& stokes, 00134 Bool linear, Bool tabular, Bool overwrite, 00135 Bool silent=False 00136 ); 00137 00138 // Function to bin up (average data) one axis of an N-D MaskedArray. The interface 00139 // is pretty specific to a particular application. It's here because 00140 // its implemented with ImageRebin. On input, the output MA *must* 00141 // have zero shape. The input and output Coordinates must have the 00142 // same type and have only one axis (Linear,Spectral & Tabular). 00143 // The output coordinate is adjusted for the binning. The binning 00144 // factor does not have to fit integrally into the shape of the specified 00145 // axis. 00146 template <typename T> 00147 static void bin (MaskedArray<T>& out, Coordinate& coordOut, 00148 const MaskedArray<T>& in, const Coordinate& coordIn, 00149 uInt axis, uInt bin); 00150 00151 // This function converts pixel coordinates to world coordinates. You 00152 // specify a vector of pixel coordinates (<src>pixels</src>) for only one 00153 // axis, the <src>pixelAxis</src>. For the other pixel axes in the 00154 // <src>CoordinateSystem</src>, if a pixel axis "i" is found in the 00155 // <src>CursorAxes</src> vector, its pixel coordinate is set to 00156 // the average of the selected region from the image for that axis 00157 // (<src>(blc(i)+trc(i))/2)</src>), otherwise it is set to the reference pixel. 00158 // The vector of world coordinates for <src>pixelAxis</src> is returned as formatted 00159 // Strings. If for some reason it can't make the conversion, the element 00160 // element is returned as "?" Returns <src>False</src> if the lengths of 00161 // <<src>blc</src> and <src>trc</src> are not equal to the number of pixel axes 00162 // in the coordinate system. 00163 static Bool pixToWorld ( 00164 Vector<String>& sWorld, 00165 const CoordinateSystem& cSys, 00166 const Int& pixelAxis, 00167 const Vector<Int>& cursorAxes, 00168 const IPosition& blc, 00169 const IPosition& trc, 00170 const Vector<Double>& pixels, 00171 const Int& prec, 00172 const Bool usePrecForMixed=False 00173 ); 00174 00175 // Convert long axis names "Right Ascension", "Declination", "Frequency" and 00176 // "Velocity" to "RA", "Dec", "Freq", "Vel" respectively. Unknown strings 00177 // are returned as given. 00178 static String shortAxisName (const String& axisName); 00179 00180 // write the specified image and add the specified pixels to it. 00181 // Currently no checks are done to ensure the pixel array size and 00182 // mapShape are compatible; the caller is responsible for this check. 00183 static void writeImage( 00184 const TiledShape& mapShape, 00185 const CoordinateSystem& coordinateInfo, 00186 const String& imageName, 00187 const Array<Float>& pixels, LogIO& log, 00188 const Array<Bool>& pixelMask = Array<Bool>() 00189 ); 00190 00191 static GaussianBeam makeFakeBeam( 00192 LogIO& logIO, const CoordinateSystem& csys, 00193 Bool suppressWarnings = False 00194 ); 00195 00196 static void getUnitAndDoppler( 00197 String& xUnit, String& doppler, 00198 const uInt axis, const CoordinateSystem& csys 00199 ); 00200 }; 00201 00202 00203 00204 } //# NAMESPACE CASACORE - END 00205 00206 #ifndef CASACORE_NO_AUTO_TEMPLATES 00207 #include <casacore/images/Images/ImageUtilities2.tcc> 00208 #endif //# CASACORE_NO_AUTO_TEMPLATES 00209 #endif