casacore
ImageUtilities.h
Go to the documentation of this file.
1 //# ImageUtilities.h: Some utility functions handy for accessing images
2 //# Copyright (C) 1996,1997,1999,2000,2001,2002
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //#
27 //# $Id$
28 #ifndef IMAGES_IMAGEUTILITIES_H
29 #define IMAGES_IMAGEUTILITIES_H
30 
31 
32 #include <casacore/casa/aips.h>
33 #include <casacore/scimath/Mathematics/GaussianBeam.h>
34 #include <casacore/lattices/Lattices/TiledShape.h>
35 #include <casacore/casa/Arrays/ArrayFwd.h>
36 #include <casacore/casa/Utilities/PtrHolder.h>
37 #include <casacore/casa/Utilities/CountedPtr.h>
38 
39 namespace casacore { //# NAMESPACE CASACORE - BEGIN
40 
41 //# Forward Declarations
42 template <class T> class ImageInterface;
43 template <class T> class Quantum;
44 template <class T> class PtrHolder;
45 class CoordinateSystem;
46 class Coordinate;
47 class String;
48 class IPosition;
49 class LogIO;
50 class AxesSpecifier;
51 class ImageAttrHandler;
52 
53 //
54 // <summary>
55 // Utility functions for Image manipulation
56 // </summary>
57 //
58 //
59 // <use visibility=export>
60 //
61 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
62 // </reviewed>
63 //
64 // <prerequisite>
65 // <li> IPosition
66 // <li> Arrays
67 // <li> Lattice
68 // </prerequisite>
69 //
70 // <synopsis>
71 // Some helpful static functions that are common to some of my image
72 // analysis application classes.
73 // </synopsis>
74 //
75 // <motivation>
76 // I needed some bits and pieces. My goal isto move this rag-tag bunch
77 // out of here into other classes as time goes on. So far
78 // I have eliminated 80% of the original !
79 // </motivation>
80 //
81 // <todo asof="1996/11/27">
82 // <li>
83 // </todo>
84 
85 
87 {
88 public:
89  // Open disk image (can be any registered image). Exception
90  // if fileName empty or file does not exist or file is not
91  // of legal image type. For Casacore images, the default mask is
92  // applied.
93  // <group>
94  template<class T>
95  static void openImage (PtrHolder<ImageInterface<T> >& image,
96  const String& fileName);
97 
98  template<class T>
99  static void openImage (ImageInterface<T>*& image,
100  const String& fileName);
101 
102  template<class T>
103  static std::shared_ptr<ImageInterface<T> > openImage (const String& fileName);
104 // </group>
105 
106 // Copy MiscInfo, ImageInfo, brightness unit and logger (history) from in to out
107  template <typename T, typename U>
109  const ImageInterface<U>& in,
110  Bool copyImageInfo = True);
111 
112 // Copy a mask from one image to another
113  template <typename T, typename U>
114  static void copyMask (ImageInterface<T>& out,
115  const ImageInterface<U>& in,
116  const String& maskOut, const String& maskIn,
117  AxesSpecifier axesSpecifier);
118 
119  // Copy the attributes from one image to another.
120  static void copyAttributes (ImageAttrHandler& out,
121  ImageAttrHandler& in);
122 
123 // Add one degenerate axis for each of the specified coordinate types.
124 // If the outfile string is given the new image is a PagedImage.
125 // If the outfile string is empty, the new image is a TempImage.
126  template <typename T>
127  static void addDegenerateAxes (
128  LogIO& os,
129  PtrHolder<ImageInterface<T> >& outImage,
130  const ImageInterface<T>& inImage,
131  const String& outFile, Bool direction,
132  Bool spectral, const String& stokes,
133  Bool linear, Bool tabular, Bool overwrite,
134  Bool silent=False
135  );
136 
137 // Function to bin up (average data) one axis of an N-D MaskedArray. The interface
138 // is pretty specific to a particular application. It's here because
139 // its implemented with ImageRebin. On input, the output MA *must*
140 // have zero shape. The input and output Coordinates must have the
141 // same type and have only one axis (Linear,Spectral & Tabular).
142 // The output coordinate is adjusted for the binning. The binning
143 // factor does not have to fit integrally into the shape of the specified
144 // axis.
145  template <typename T>
146  static void bin (MaskedArray<T>& out, Coordinate& coordOut,
147  const MaskedArray<T>& in, const Coordinate& coordIn,
148  uInt axis, uInt bin);
149 
150 // This function converts pixel coordinates to world coordinates. You
151 // specify a vector of pixel coordinates (<src>pixels</src>) for only one
152 // axis, the <src>pixelAxis</src>. For the other pixel axes in the
153 // <src>CoordinateSystem</src>, if a pixel axis "i" is found in the
154 // <src>CursorAxes</src> vector, its pixel coordinate is set to
155 // the average of the selected region from the image for that axis
156 // (<src>(blc(i)+trc(i))/2)</src>), otherwise it is set to the reference pixel.
157 // The vector of world coordinates for <src>pixelAxis</src> is returned as formatted
158 // Strings. If for some reason it can't make the conversion, the element
159 // element is returned as "?" Returns <src>False</src> if the lengths of
160 // <<src>blc</src> and <src>trc</src> are not equal to the number of pixel axes
161 // in the coordinate system.
162  static Bool pixToWorld (
163  Vector<String>& sWorld,
164  const CoordinateSystem& cSys,
165  const Int& pixelAxis,
166  const Vector<Int>& cursorAxes,
167  const IPosition& blc,
168  const IPosition& trc,
169  const Vector<Double>& pixels,
170  const Int& prec,
171  const Bool usePrecForMixed=False
172  );
173 
174 // Convert long axis names "Right Ascension", "Declination", "Frequency" and
175 // "Velocity" to "RA", "Dec", "Freq", "Vel" respectively. Unknown strings
176 // are returned as given.
177  static String shortAxisName (const String& axisName);
178 
179  // write the specified image and add the specified pixels to it.
180  // Currently no checks are done to ensure the pixel array size and
181  // mapShape are compatible; the caller is responsible for this check.
182  static void writeImage(
183  const TiledShape& mapShape,
184  const CoordinateSystem& coordinateInfo,
185  const String& imageName,
186  const Array<Float>& pixels, LogIO& log,
187  const Array<Bool>& pixelMask = Array<Bool>()
188  );
189 
191  LogIO& logIO, const CoordinateSystem& csys,
192  Bool suppressWarnings = False
193  );
194 
195  static void getUnitAndDoppler(
196  String& xUnit, String& doppler,
197  const uInt axis, const CoordinateSystem& csys
198  );
199 };
200 
201 
202 
203 } //# NAMESPACE CASACORE - END
204 
205 #ifndef CASACORE_NO_AUTO_TEMPLATES
206 #include <casacore/images/Images/ImageUtilities2.tcc>
207 #endif //# CASACORE_NO_AUTO_TEMPLATES
208 #endif
static String shortAxisName(const String &axisName)
Convert long axis names "Right Ascension", "Declination", "Frequency" and "Velocity" to "RA",...
static void openImage(ImageInterface< T > *&image, const String &fileName)
static Bool pixToWorld(Vector< String > &sWorld, const CoordinateSystem &cSys, const Int &pixelAxis, const Vector< Int > &cursorAxes, const IPosition &blc, const IPosition &trc, const Vector< Double > &pixels, const Int &prec, const Bool usePrecForMixed=False)
This function converts pixel coordinates to world coordinates.
static void addDegenerateAxes(LogIO &os, PtrHolder< ImageInterface< T > > &outImage, const ImageInterface< T > &inImage, const String &outFile, Bool direction, Bool spectral, const String &stokes, Bool linear, Bool tabular, Bool overwrite, Bool silent=False)
Add one degenerate axis for each of the specified coordinate types.
static void copyMask(ImageInterface< T > &out, const ImageInterface< U > &in, const String &maskOut, const String &maskIn, AxesSpecifier axesSpecifier)
Copy a mask from one image to another.
static void getUnitAndDoppler(String &xUnit, String &doppler, const uInt axis, const CoordinateSystem &csys)
static void openImage(PtrHolder< ImageInterface< T > > &image, const String &fileName)
Open disk image (can be any registered image).
static void writeImage(const TiledShape &mapShape, const CoordinateSystem &coordinateInfo, const String &imageName, const Array< Float > &pixels, LogIO &log, const Array< Bool > &pixelMask=Array< Bool >())
write the specified image and add the specified pixels to it.
static void copyAttributes(ImageAttrHandler &out, ImageAttrHandler &in)
Copy the attributes from one image to another.
static void bin(MaskedArray< T > &out, Coordinate &coordOut, const MaskedArray< T > &in, const Coordinate &coordIn, uInt axis, uInt bin)
Function to bin up (average data) one axis of an N-D MaskedArray.
static void copyMiscellaneous(ImageInterface< T > &out, const ImageInterface< U > &in, Bool copyImageInfo=True)
Copy MiscInfo, ImageInfo, brightness unit and logger (history) from in to out.
static GaussianBeam makeFakeBeam(LogIO &logIO, const CoordinateSystem &csys, Bool suppressWarnings=False)
static std::shared_ptr< ImageInterface< T > > openImage(const String &fileName)
String: the storage and methods of handling collections of characters.
Definition: String.h:225
this file contains all the compiler specific defines
Definition: mainpage.dox:28
const Bool False
Definition: aipstype.h:44
unsigned int uInt
Definition: aipstype.h:51
LatticeExprNode log(const LatticeExprNode &expr)
int Int
Definition: aipstype.h:50
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
PtrHolder(const PtrHolder< T > &other)
const Bool True
Definition: aipstype.h:43