casacore
Loading...
Searching...
No Matches
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: casa-feedback@nrao.edu.
21// # Postal address: AIPS++ Project Office
22// # National Radio Astronomy Observatory
23// # 520 Edgemont Road
24// # Charlottesville, VA 22903-2475 USA
25#ifndef IMAGES_IMAGEUTILITIES_H
26#define IMAGES_IMAGEUTILITIES_H
27
28#include <casacore/casa/aips.h>
29#include <casacore/scimath/Mathematics/GaussianBeam.h>
30#include <casacore/lattices/Lattices/TiledShape.h>
31#include <casacore/casa/Arrays/ArrayFwd.h>
32#include <memory>
33
34namespace casacore { // # NAMESPACE CASACORE - BEGIN
35
36// # Forward Declarations
37template <class T>
38class ImageInterface;
39template <class T>
40class Quantum;
42class Coordinate;
43class String;
44class IPosition;
45class LogIO;
46class AxesSpecifier;
48
49//
50// <summary>
51// Utility functions for Image manipulation
52// </summary>
53//
54//
55// <use visibility=export>
56//
57// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
58// </reviewed>
59//
60// <prerequisite>
61// <li> IPosition
62// <li> Arrays
63// <li> Lattice
64// </prerequisite>
65//
66// <synopsis>
67// Some helpful static functions that are common to some of my image
68// analysis application classes.
69// </synopsis>
70//
71// <motivation>
72// I needed some bits and pieces. My goal isto move this rag-tag bunch
73// out of here into other classes as time goes on. So far
74// I have eliminated 80% of the original !
75// </motivation>
76//
77// <todo asof="1996/11/27">
78// <li>
79// </todo>
80
82 public:
83 // Open disk image (can be any registered image). Exception
84 // if fileName empty or file does not exist or file is not
85 // of legal image type. For Casacore images, the default mask is
86 // applied.
87 // <group>
88 template <class T>
89 static void openImage(std::unique_ptr<ImageInterface<T>>& image, const String& fileName);
90
91 template <class T>
92 static void openImage(ImageInterface<T>*& image, const String& fileName);
93
94 template <class T>
95 static std::shared_ptr<ImageInterface<T>> openImage(const String& fileName);
96 // </group>
97
98 // Copy MiscInfo, ImageInfo, brightness unit and logger (history) from in to out
99 template <typename T, typename U>
101 Bool copyImageInfo = True);
102
103 // Copy a mask from one image to another
104 template <typename T, typename U>
105 static void copyMask(ImageInterface<T>& out, const ImageInterface<U>& in, const String& maskOut,
106 const String& maskIn, AxesSpecifier axesSpecifier);
107
108 // Copy the attributes from one image to another.
110
111 // Add one degenerate axis for each of the specified coordinate types.
112 // If the outfile string is given the new image is a PagedImage.
113 // If the outfile string is empty, the new image is a TempImage.
114 template <typename T>
115 static void addDegenerateAxes(LogIO& os, std::unique_ptr<ImageInterface<T>>& outImage,
116 const ImageInterface<T>& inImage, const String& outFile,
117 Bool direction, Bool spectral, const String& stokes, Bool linear,
118 Bool tabular, Bool overwrite, Bool silent = False);
119
120 // Function to bin up (average data) one axis of an N-D MaskedArray. The interface
121 // is pretty specific to a particular application. It's here because
122 // its implemented with ImageRebin. On input, the output MA *must*
123 // have zero shape. The input and output Coordinates must have the
124 // same type and have only one axis (Linear,Spectral & Tabular).
125 // The output coordinate is adjusted for the binning. The binning
126 // factor does not have to fit integrally into the shape of the specified
127 // axis.
128 template <typename T>
129 static void bin(MaskedArray<T>& out, Coordinate& coordOut, const MaskedArray<T>& in,
130 const Coordinate& coordIn, uInt axis, uInt bin);
131
132 // This function converts pixel coordinates to world coordinates. You
133 // specify a vector of pixel coordinates (<src>pixels</src>) for only one
134 // axis, the <src>pixelAxis</src>. For the other pixel axes in the
135 // <src>CoordinateSystem</src>, if a pixel axis "i" is found in the
136 // <src>CursorAxes</src> vector, its pixel coordinate is set to
137 // the average of the selected region from the image for that axis
138 // (<src>(blc(i)+trc(i))/2)</src>), otherwise it is set to the reference pixel.
139 // The vector of world coordinates for <src>pixelAxis</src> is returned as formatted
140 // Strings. If for some reason it can't make the conversion, the element
141 // element is returned as "?" Returns <src>False</src> if the lengths of
142 // <<src>blc</src> and <src>trc</src> are not equal to the number of pixel axes
143 // in the coordinate system.
144 static Bool pixToWorld(Vector<String>& sWorld, const CoordinateSystem& cSys, const Int& pixelAxis,
145 const Vector<Int>& cursorAxes, const IPosition& blc, const IPosition& trc,
146 const Vector<Double>& pixels, const Int& prec,
147 const Bool usePrecForMixed = False);
148
149 // Convert long axis names "Right Ascension", "Declination", "Frequency" and
150 // "Velocity" to "RA", "Dec", "Freq", "Vel" respectively. Unknown strings
151 // are returned as given.
152 static String shortAxisName(const String& axisName);
153
154 // write the specified image and add the specified pixels to it.
155 // Currently no checks are done to ensure the pixel array size and
156 // mapShape are compatible; the caller is responsible for this check.
157 static void writeImage(const TiledShape& mapShape, const CoordinateSystem& coordinateInfo,
158 const String& imageName, const Array<Float>& pixels, LogIO& log,
159 const Array<Bool>& pixelMask = Array<Bool>());
160
162 Bool suppressWarnings = False);
163
164 static void getUnitAndDoppler(String& xUnit, String& doppler, const uInt axis,
165 const CoordinateSystem& csys);
166};
167
168} // namespace casacore
169
170#ifndef CASACORE_NO_AUTO_TEMPLATES
171#include <casacore/images/Images/ImageUtilities2.tcc>
172#endif // # CASACORE_NO_AUTO_TEMPLATES
173#endif
static String shortAxisName(const String &axisName)
Convert long axis names "Right Ascension", "Declination", "Frequency" and "Velocity" to "RA",...
static void openImage(std::unique_ptr< ImageInterface< T > > &image, const String &fileName)
Open disk image (can be any registered image).
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 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 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 addDegenerateAxes(LogIO &os, std::unique_ptr< 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 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 std::shared_ptr< ImageInterface< T > > openImage(const String &fileName)
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)
String: the storage and methods of handling collections of characters.
Definition String.h:355
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
unsigned int uInt
Definition aipstype.h:49
LatticeExprNode log(const LatticeExprNode &expr)
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
const Bool True
Definition aipstype.h:41