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