casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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>
37 
38 namespace casacore { //# NAMESPACE CASACORE - BEGIN
39 
40 //# Forward Declarations
41 template <class T> class ImageInterface;
42 template <class T> class Vector;
43 template <class T> class Quantum;
44 template <class T> class MaskedArray;
45 template <class T> class PtrHolder;
46 class CoordinateSystem;
47 class Coordinate;
48 class String;
49 class IPosition;
50 class LogIO;
51 class AxesSpecifier;
52 class ImageAttrHandler;
53 
54 //
55 // <summary>
56 // Utility functions for Image manipulation
57 // </summary>
58 //
59 //
60 // <use visibility=export>
61 //
62 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
63 // </reviewed>
64 //
65 // <prerequisite>
66 // <li> IPosition
67 // <li> Arrays
68 // <li> Lattice
69 // </prerequisite>
70 //
71 // <synopsis>
72 // Some helpful static functions that are common to some of my image
73 // analysis application classes.
74 // </synopsis>
75 //
76 // <motivation>
77 // I needed some bits and pieces. My goal isto move this rag-tag bunch
78 // out of here into other classes as time goes on. So far
79 // I have eliminated 80% of the original !
80 // </motivation>
81 //
82 // <todo asof="1996/11/27">
83 // <li>
84 // </todo>
85 
86 
88 {
89 public:
90  // Open disk image (can be any registered image). Exception
91  // if fileName empty or file does not exist or file is not
92  // of legal image type. For Casacore images, the default mask is
93  // applied.
94  // <group>
95  template<class T>
96  static void openImage (PtrHolder<ImageInterface<T> >& image,
97  const String& fileName);
98 
99  template<class T>
100  static void openImage (ImageInterface<T>*& image,
101  const String& fileName);
102 
103  template<class T>
104  static std::shared_ptr<ImageInterface<T> > openImage (const String& fileName);
105 // </group>
106 
107 // Copy MiscInfo, ImageInfo, brightness unit and logger (history) from in to out
108  template <typename T, typename U>
109  static void copyMiscellaneous (ImageInterface<T>& out,
110  const ImageInterface<U>& in,
111  Bool copyImageInfo = True);
112 
113 // Copy a mask from one image to another
114  template <typename T, typename U>
115  static void copyMask (ImageInterface<T>& out,
116  const ImageInterface<U>& in,
117  const String& maskOut, const String& maskIn,
118  AxesSpecifier axesSpecifier);
119 
120  // Copy the attributes from one image to another.
121  static void copyAttributes (ImageAttrHandler& out,
122  ImageAttrHandler& in);
123 
124 // Add one degenerate axis for each of the specified coordinate types.
125 // If the outfile string is given the new image is a PagedImage.
126 // If the outfile string is empty, the new image is a TempImage.
127  template <typename T>
128  static void addDegenerateAxes (
129  LogIO& os,
130  PtrHolder<ImageInterface<T> >& outImage,
131  const ImageInterface<T>& inImage,
132  const String& outFile, Bool direction,
133  Bool spectral, const String& stokes,
134  Bool linear, Bool tabular, Bool overwrite,
135  Bool silent=False
136  );
137 
138 // Function to bin up (average data) one axis of an N-D MaskedArray. The interface
139 // is pretty specific to a particular application. It's here because
140 // its implemented with ImageRebin. On input, the output MA *must*
141 // have zero shape. The input and output Coordinates must have the
142 // same type and have only one axis (Linear,Spectral & Tabular).
143 // The output coordinate is adjusted for the binning. The binning
144 // factor does not have to fit integrally into the shape of the specified
145 // axis.
146  template <typename T>
147  static void bin (MaskedArray<T>& out, Coordinate& coordOut,
148  const MaskedArray<T>& in, const Coordinate& coordIn,
149  uInt axis, uInt bin);
150 
151 // This function converts pixel coordinates to world coordinates. You
152 // specify a vector of pixel coordinates (<src>pixels</src>) for only one
153 // axis, the <src>pixelAxis</src>. For the other pixel axes in the
154 // <src>CoordinateSystem</src>, if a pixel axis "i" is found in the
155 // <src>CursorAxes</src> vector, its pixel coordinate is set to
156 // the average of the selected region from the image for that axis
157 // (<src>(blc(i)+trc(i))/2)</src>), otherwise it is set to the reference pixel.
158 // The vector of world coordinates for <src>pixelAxis</src> is returned as formatted
159 // Strings. If for some reason it can't make the conversion, the element
160 // element is returned as "?" Returns <src>False</src> if the lengths of
161 // <<src>blc</src> and <src>trc</src> are not equal to the number of pixel axes
162 // in the coordinate system.
163  static Bool pixToWorld (
164  Vector<String>& sWorld,
165  const CoordinateSystem& cSys,
166  const Int& pixelAxis,
167  const Vector<Int>& cursorAxes,
168  const IPosition& blc,
169  const IPosition& trc,
170  const Vector<Double>& pixels,
171  const Int& prec,
172  const Bool usePrecForMixed=False
173  );
174 
175 // Convert long axis names "Right Ascension", "Declination", "Frequency" and
176 // "Velocity" to "RA", "Dec", "Freq", "Vel" respectively. Unknown strings
177 // are returned as given.
178  static String shortAxisName (const String& axisName);
179 
180  // write the specified image and add the specified pixels to it.
181  // Currently no checks are done to ensure the pixel array size and
182  // mapShape are compatible; the caller is responsible for this check.
183  static void writeImage(
184  const TiledShape& mapShape,
185  const CoordinateSystem& coordinateInfo,
186  const String& imageName,
187  const Array<Float>& pixels, LogIO& log,
188  const Array<Bool>& pixelMask = Array<Bool>()
189  );
190 
191  static GaussianBeam makeFakeBeam(
192  LogIO& logIO, const CoordinateSystem& csys,
193  Bool suppressWarnings = False
194  );
195 
196  static void getUnitAndDoppler(
197  String& xUnit, String& doppler,
198  const uInt axis, const CoordinateSystem& csys
199  );
200 };
201 
202 
203 
204 } //# NAMESPACE CASACORE - END
205 
206 #ifndef CASACORE_NO_AUTO_TEMPLATES
207 #include <casacore/images/Images/ImageUtilities2.tcc>
208 #endif //# CASACORE_NO_AUTO_TEMPLATES
209 #endif
Utility functions for Image manipulation.
A Vector of integers, for indexing into Array&lt;T&gt; objects.
Definition: IPosition.h:119
A 1-D Specialization of the Array class.
int Int
Definition: aipstype.h:50
std::vector< double > Vector
Definition: ds9context.h:24
LatticeExprNode log(const LatticeExprNode &expr)
static void openImage(PtrHolder< ImageInterface< T > > &image, const String &fileName)
Open disk image (can be any registered image).
static void copyAttributes(ImageAttrHandler &out, ImageAttrHandler &in)
Copy the attributes from one image to another.
PtrHolder(const PtrHolder< T > &other)
ostream-like interface to creating log messages.
Definition: LogIO.h:167
static void getUnitAndDoppler(String &xUnit, String &doppler, const uInt axis, const CoordinateSystem &csys)
Hold and delete pointers not deleted by object destructors.
Abstract base class for an image attributes handler.
Specification of axes to keep or remove.
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.
Represents a Gaussian restoring beam associated with an image.
Definition: GaussianBeam.h:68
Class for masking an Array for operations on that Array.
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 String shortAxisName(const String &axisName)
Convert long axis names &quot;Right Ascension&quot;, &quot;Declination&quot;, &quot;Frequency&quot; and &quot;Velocity&quot; to &quot;RA&quot;...
Define the shape and tile shape.
Definition: TiledShape.h:99
A base class for astronomical images.
Interface for converting between world and pixel coordinates.
Definition: Coordinate.h:139
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
const Bool False
Definition: aipstype.h:44
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 GaussianBeam makeFakeBeam(LogIO &logIO, const CoordinateSystem &csys, Bool suppressWarnings=False)
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.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
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.
const Bool True
Definition: aipstype.h:43
Interconvert pixel and world coordinates.
unsigned int uInt
Definition: aipstype.h:51
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.
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42