PixelValueManipulator.h

Go to the documentation of this file.
00001 #ifndef IMAGEANALYSIS_PIXELVALUEMANIPULATOR_H
00002 #define IMAGEANALYSIS_PIXELVALUEMANIPULATOR_H
00003 
00004 #include <imageanalysis/ImageAnalysis/ImageTask.h>
00005 
00006 #include <imageanalysis/ImageAnalysis/ImageCollapserData.h>
00007 #include <imageanalysis/ImageAnalysis/PixelValueManipulatorData.h>
00008 
00009 
00010 namespace casa {
00011 
00012 template <class T> class PixelValueManipulator : public ImageTask<T> {
00013         // <summary>
00014         // Top level interface for getting and setting image pixel values.
00015         // </summary>
00016 
00017         // <reviewed reviewer="" date="" tests="" demos="">
00018         // </reviewed>
00019 
00020         // <prerequisite>
00021         // </prerequisite>
00022 
00023         // <etymology>
00024         // Manipulates pixel values.
00025         // </etymology>
00026 
00027         // <synopsis>
00028         // Top level interface for getting and setting image pixel values.
00029         // </synopsis>
00030 
00031         // <example>
00032         // </example>
00033 
00034 public:
00035 
00036         PixelValueManipulator() = delete;
00037 
00038         // regionRec = 0 => no region selected, full image used
00039         // mask = "" => No additional mask specification, although image default mask will be used
00040         // if one exists.
00041         PixelValueManipulator(
00042                 const SPCIIT image, const Record *const regionRec,
00043                 const String& mask, Bool verboseDuringConstruction=True
00044         );
00045 
00046         ~PixelValueManipulator() {}
00047 
00048         static void addNoise(
00049                 SPIIT image, const String& type, const Record& region, const Vector<Double>& pars,
00050                 Bool zero, const std::pair<Int, Int> *const &seeds
00051         );
00052 
00053         // <src>dirFrame</src> and <src>freqFrame</src> are the codes for the
00054         // frames for which it is desired that the returned measures should be specified.
00055         // In both cases, one can specify "native" for the native coordinate frame,
00056         // "cl" for the conversion layer frame, or any valid frame string from MDirection::showType()
00057         // or MFrequency::showType().
00058         static Record* coordMeasures(
00059                 Quantum<T>& intensity, Record& direction,
00060                 Record& frequency, Record& velocity,
00061                 SPCIIT image, const Vector<Double>& pixel,
00062                 const String& dirFrame, const String& freqFrame
00063         );
00064 
00065         // set axes to average over. If invert is True, select all axes other than
00066         // the specified axes to average over.
00067         void setAxes(const IPosition& axes, Bool invert=False);
00068 
00069         // Get pixel values, pixel mask values, etc.
00070         // The return Record has the following fields:
00071         // 'values' => Array<T> of pixel values
00072         // 'mask'   => Array<Bool> of pixel mask values
00073         Record get() const;
00074 
00075         // get a slice through the image. The values are interpolated at regular
00076         // intervals to provide samples at npts number of points. x and y are
00077         // in pixel coordinates
00078 
00079         static Record* getSlice(
00080                 SPCIIT image, const Vector<Double>& x, const Vector<Double>& y,
00081                 const Vector<Int>& axes, const Vector<Int>& coord,
00082                 Int npts=0, const String& method="linear"
00083         );
00084 
00085         static void put(
00086                 SPIIT image, const Array<T>& pixelsArray, const Vector<Int>& blc,
00087                 const Vector<Int>& inc, Bool list,
00088                 Bool locking, Bool replicate
00089         );
00090 
00091         static Bool putRegion(
00092             SPIIT image, const Array<T>& pixels,
00093             const Array<Bool>& mask, Record& region, Bool list,
00094             Bool usemask, Bool replicateArray
00095         );
00096 
00097         // get the aggregated values along the specified pixel axis using the region and mask at construction
00098         // and any other mask the image may have. Supported values of <src>function</src> are (case-insensitive,
00099         // minimum match) those supported by ImageCollapser, ie "flux", "max", "mean", "median", "min", "rms",
00100         // "sqrtsum", "sqrtsum_npix", sqrtsum_npix_beam", "stddev", "sum", "variance",  and "zero". Aggregation
00101         // of values occurs along all axes orthogonal to the one specified. One may specify the unit in which
00102         // coordinate values are calculated using the <src>unit</src> parameter. If unit starts with "pix", then
00103         // pixel coordinates are calculated, world coordinates otherwise. If pixel coordinates, the values are
00104         // relative to the zeroth pixel on the corresponding axis of the input image.  If specified and it
00105         // doesn't start with "pix", the unit must be conformant with
00106         // the unit of <src>axis</src> in the coordinate system of the image, or it must be a unit that this axis
00107         // can be readily converted to (eg km/s if the axis is a frequency axis with base unit of Hz).
00108         // If the selected axis is the spectral axis and if the unit is chosen to be something other
00109         // than the native spectral coordinate unit (such as velocity or wavelength for a native frequency unit),
00110         // <src>specType</src> indicates the system to use when converting the frequency. Values of RELATVISTIC,
00111         // RADIO_VELOCITY, and OPTICAL_VELOCITY are only permitted if <src>unit</src> represents a velocity unit.
00112         // Values of WAVELENGTH and AIR_WAVELENGTH are only permitted if <src>unit</src> represents a length unit.
00113         // For a velocity unit, DEFAULT is equivalent to RELATIVISTIC. For a length unit, DEFAULT is equivalent to
00114         // WAVELENGTH.
00115         // If the selected axis is the spectral axis and <src>unit</src> is a velocity unit,
00116         // <src>restFreq</src> represents the rest frequency with respect to which the velocity scale should be
00117         // calculated. If null, the rest frequency associated with the spectral coordinate is used.
00118         // If the selected axis is the spectral axis, and <src>unit</src> is a frequency unit,
00119         // <src>frame</src> represents the frame of reference with respect to which the frequency scale should be
00120         // calculated. If empty, the reference frame associated with the spectral coordinate is used.
00121         // The return Record has the following keys: "values" is a Vector<T> containing the aggregate pixel values,
00122         // "mask" is the associated mask values (Vector<Bool>), "coords" is a Vector<Double> of coordinate values,
00123         // and "xUnit" is a String containing the coordinate unit, and "yUnit" is a string containing the
00124         // ordinate unit.
00125         Record getProfile(
00126                 uInt axis, const String& function, const String& unit,
00127                 PixelValueManipulatorData::SpectralType specType=PixelValueManipulatorData::DEFAULT,
00128                 const Quantity *const restFreq=nullptr, const String& frame=""
00129         );
00130 
00131         Record getProfile(
00132                 uInt axis, ImageCollapserData::AggregateType function, const String& unit,
00133                 PixelValueManipulatorData::SpectralType specType=PixelValueManipulatorData::DEFAULT,
00134                 const Quantity *const restFreq=nullptr, const String& frame=""
00135         );
00136 
00137         String getClass() const { return _className; }
00138 
00139         // region refers to the region in the image to be inserted, not the
00140         // region that was chosen at object construction
00141         static void insert(
00142                 ImageInterface<T>& target, const ImageInterface<T>& image, const Record& region,
00143                 const Vector<Double>& locatePixel, Bool verbose
00144         );
00145 
00146         // Make a block of regions from a Record
00147         // public so ImageAnalysis can use it, once those methods have been
00148         // excised, make private
00149         static void makeRegionBlock(
00150             PtrBlock<const ImageRegion*>& regions,
00151             const Record& Regions
00152         );
00153 
00154         Record pixelValue(const Vector<Int>& pixel) const;
00155 
00156         void pixelValue(
00157             Bool& offImage, Quantum<T>& value, Bool& mask,
00158             Vector<Int>& pos
00159         ) const;
00160 
00161         // set specified pixels or mask equal to provided scalar value
00162         static Bool set(
00163             SPIIF image, const String& pixels, const Int pixelmask,
00164             Record& region, const Bool list = false
00165         );
00166 
00167         // set region name for logging purposes. Only used if the logfile is set.
00168         void setRegionName(const String& rname) { _regionName = rname; }
00169 
00170 protected:
00171         CasacRegionManager::StokesControl _getStokesControl() const {
00172                 return CasacRegionManager::USE_ALL_STOKES;
00173         }
00174 
00175         std::vector<Coordinate::Type> _getNecessaryCoordinates() const {
00176                 return std::vector<Coordinate::Type>();
00177         }
00178 
00179         Bool _hasLogfileSupport() const { return True; }
00180 
00181     Bool _supportsMultipleRegions() const {return True;}
00182 
00183 private:
00184     IPosition _axes, _lastChunkShape;
00185     String _regionName;
00186     const static String _className;
00187 
00188         void _checkUnit(
00189                 const String& unit, const CoordinateSystem& csys,
00190                 PixelValueManipulatorData::SpectralType specType
00191         ) const;
00192 
00193         Record _doWorld(
00194                 SPIIT collapsed, const String& unit,
00195                 PixelValueManipulatorData::SpectralType specType,
00196                 const Quantity *const restFreq, const String& frame,
00197                 uInt axis
00198         ) const;
00199 
00200         void _doNoncomformantUnit(
00201                 Vector<Double>& coords, const CoordinateSystem& csys,
00202                 const String& unit, PixelValueManipulatorData::SpectralType specType,
00203                 const Quantity *const restFreq, const String& axisUnit
00204         ) const;
00205 
00206         Vector<uInt> _npts(uInt axis) const;
00207 };
00208 
00209 }
00210 
00211 #ifndef AIPS_NO_TEMPLATE_SRC
00212 #include <imageanalysis/ImageAnalysis/PixelValueManipulator.tcc>
00213 #endif //# AIPS_NO_TEMPLATE_SRC
00214 
00215 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1