LSSTApplications  11.0-13-gbb96280,12.1+18,12.1+7,12.1-1-g14f38d3+72,12.1-1-g16c0db7+5,12.1-1-g5961e7a+84,12.1-1-ge22e12b+23,12.1-11-g06625e2+4,12.1-11-g0d7f63b+4,12.1-19-gd507bfc,12.1-2-g7dda0ab+38,12.1-2-gc0bc6ab+81,12.1-21-g6ffe579+2,12.1-21-gbdb6c2a+4,12.1-24-g941c398+5,12.1-3-g57f6835+7,12.1-3-gf0736f3,12.1-37-g3ddd237,12.1-4-gf46015e+5,12.1-5-g06c326c+20,12.1-5-g648ee80+3,12.1-5-gc2189d7+4,12.1-6-ga608fc0+1,12.1-7-g3349e2a+5,12.1-7-gfd75620+9,12.1-9-g577b946+5,12.1-9-gc4df26a+10
LSSTDataManagementBasePackage
Namespaces | Typedefs | Functions | Variables
lsst.afw.display Namespace Reference

Namespaces

 ds9
 
 ds9Regions
 
 interface
 
 rgb
 
 utils
 
 virtualDevice
 

Typedefs

typedef
detection::FootprintSet::FootprintList 
FootprintList
 

Functions

template<class T >
std::pair< double, double > getZScale (image::Image< T > const &image, int const nSamples=1000, double const contrast=0.25)
 Calculate an IRAF/ds9-style zscaling. More...
 
 if (width!=gim.getWidth()||height!=gim.getHeight()||x0!=gim.getX0()||y0!=gim.getY0())
 
SetPixels< typename
ImageT::Image > setR * 
rim ()), setG(*gim.getImage()), setB(*bim.getImage()
 
sat merge (detection::FootprintSet(*gim.getMask(), satThresh, npixMin))
 
 for (FootprintList::const_iterator ptr=feet->begin(), end=feet->end();ptr!=end;++ptr)
 
template void replaceSaturatedPixels (image::MaskedImage< float > &rim, image::MaskedImage< float > &gim, image::MaskedImage< float > &bim, int borderWidth, float saturatedPixelValue)
 
template std::pair< double,
double > 
getZScale (image::Image< std::uint16_t > const &image, int const nSamples, double const contrast)
 
template std::pair< double,
double > 
getZScale (image::Image< float > const &image, int const nSamples, double const contrast)
 
template<typename ImageT >
void writeBasicFits (int fd, ImageT const &data, image::Wcs const *Wcs, char const *title)
 
template<typename ImageT >
void writeBasicFits (std::string const &filename, ImageT const &data, image::Wcs const *Wcs, char const *title)
 

Variables

template<typename ImageT >
void ImageT & gim
 
template<typename ImageT >
void ImageT ImageT & bim
 
template<typename ImageT >
void ImageT ImageT int borderWidth = 2
 
template<typename ImageT >
void ImageT ImageT int float saturatedPixelValue
 
template<typename ImageT >
void ImageT ImageT int float
saturatedPixelValue int const 
width = rim.getWidth()
 
template<typename ImageT >
void ImageT ImageT int float
saturatedPixelValue int const 
height = rim.getHeight()
 
int const x0 = rim.getX0()
 
int const y0 = rim.getY0()
 
bool const useMaxPixel = !std::isfinite(saturatedPixelValue)
 
int const npixMin = 1
 
afw::image::MaskPixel const SAT = rim.getMask()->getPlaneBitMask("SAT")
 
detection::Threshold const satThresh (SAT, detection::Threshold::BITMASK)
 
boost::shared_ptr< FootprintListfeet = sat.getFootprints()
 

Typedef Documentation

Examples:
spatialCellExample.cc.

Definition at line 80 of file saturated.cc.

Function Documentation

lsst::afw::display::for ( FootprintList::const_iterator  ptr = feet->begin(),
end  = feet->end(); ptr != end; ++ptr 
)
Examples:
spatialCellExample.cc.

Definition at line 82 of file saturated.cc.

82  {
83  PTR(detection::Footprint) const foot = *ptr;
84  PTR(detection::Footprint) const bigFoot = growFootprint(*foot, borderWidth);
85 
86  double sumR = 0, sumG = 0, sumB = 0; // sum of all non-saturated adjoining pixels
87  double maxR = 0, maxG = 0, maxB = 0; // maximum of non-saturated adjoining pixels
88 
89  for (detection::Footprint::SpanList::const_iterator sptr = bigFoot->getSpans().begin(),
90  send = bigFoot->getSpans().end(); sptr != send; ++sptr) {
91  PTR(detection::Span) const span = *sptr;
92 
93  int const y = span->getY() - y0;
94  if (y < 0 || y >= height) {
95  continue;
96  }
97  int sx0 = span->getX0() - x0;
98  if (sx0 < 0) {
99  sx0 = 0;
100  }
101  int sx1 = span->getX1() - x0;
102  if (sx1 >= width) {
103  sx1 = width - 1;
104  }
105 
106  for (typename ImageT::iterator
107  rptr = rim.at(sx0, y),
108  rend = rim.at(sx1 + 1, y),
109  gptr = gim.at(sx0, y),
110  bptr = bim.at(sx0, y); rptr != rend; ++rptr, ++gptr, ++bptr) {
111  if (!((rptr.mask() | gptr.mask() | bptr.mask()) & SAT)) {
112  float val = rptr.image();
113  sumR += val;
114  if (val > maxR) {
115  maxR = val;
116  }
117 
118  val = gptr.image();
119  sumG += val;
120  if (val > maxG) {
121  maxG = val;
122  }
123 
124  val = bptr.image();
125  sumB += val;
126  if (val > maxB) {
127  maxB = val;
128  }
129  }
130  }
131  }
132  // OK, we have the mean fluxes for the pixels surrounding this set of saturated pixels
133  // so we can figure out the proper values to use for the saturated ones
134  float R = 0, G = 0, B = 0; // mean intensities
135  if (sumR + sumB + sumG > 0) {
136  if (sumR > sumG) {
137  if (sumR > sumB) {
138  R = useMaxPixel ? maxR : saturatedPixelValue;
139 
140  G = (R*sumG)/sumR;
141  B = (R*sumB)/sumR;
142  } else {
143  B = useMaxPixel ? maxB : saturatedPixelValue;
144  R = (B*sumR)/sumB;
145  G = (B*sumG)/sumB;
146  }
147  } else {
148  if (sumG > sumB) {
149  G = useMaxPixel ? maxG : saturatedPixelValue;
150  R = (G*sumR)/sumG;
151  B = (G*sumB)/sumG;
152  } else {
153  B = useMaxPixel ? maxB : saturatedPixelValue;
154  R = (B*sumR)/sumB;
155  G = (B*sumG)/sumB;
156  }
157  }
158  }
159  // Now that we know R, G, and B we can fix the values
160  setR.setValue(R); setR.apply(*foot);
161  setG.setValue(G); setG.apply(*foot);
162  setB.setValue(B); setB.apply(*foot);
163  }
int y
for(FootprintList::const_iterator ptr=feet->begin(), end=feet->end();ptr!=end;++ptr)
Definition: saturated.cc:82
lsst::afw::detection::Footprint Footprint
Definition: Source.h:60
int const x0
Definition: saturated.cc:45
boost::shared_ptr< Footprint > growFootprint(Footprint const &foot, int nGrow, bool isotropic=true)
Grow a Footprint by nGrow pixels, returning a new Footprint.
void ImageT ImageT int float saturatedPixelValue int const width
Definition: saturated.cc:44
afw::image::MaskPixel const SAT
Definition: saturated.cc:73
if(width!=gim.getWidth()||height!=gim.getHeight()||x0!=gim.getX0()||y0!=gim.getY0())
Definition: saturated.cc:47
A set of pixels in an Image.
Definition: Footprint.h:62
void ImageT ImageT int float saturatedPixelValue int const height
Definition: saturated.cc:44
void ImageT & gim
Definition: Rgb.h:36
void ImageT ImageT int float saturatedPixelValue
Definition: Rgb.h:39
#define PTR(...)
Definition: base.h:41
void ImageT ImageT & bim
Definition: Rgb.h:36
bool const useMaxPixel
Definition: saturated.cc:64
int const y0
Definition: saturated.cc:45
ImageT val
Definition: CR.cc:159
SetPixels< typename ImageT::Image > setR * rim()), setG(*gim.getImage()), setB(*bim.getImage()
void ImageT ImageT int borderWidth
Definition: Rgb.h:38
template<class T >
std::pair< double, double > lsst::afw::display::getZScale ( image::Image< T > const &  image,
int const  nSamples = 1000,
double const  contrast = 0.25 
)

Calculate an IRAF/ds9-style zscaling.

To quote Frank Valdes (http://iraf.net/forum/viewtopic.php?showtopic=134139)

ZSCALE ALGORITHM

The zscale algorithm is designed to display the  image  values  near
the  median  image  value  without  the  time  consuming  process of
computing a full image histogram.  This is particularly  useful  for
astronomical  images  which  generally  have a very peaked histogram
corresponding to  the  background  sky  in  direct  imaging  or  the
continuum in a two dimensional spectrum.

The  sample  of pixels, specified by values greater than zero in the
sample mask zmask or by an  image  section,  is  selected  up  to  a
maximum  of nsample pixels.  If a bad pixel mask is specified by the
bpmask parameter then any pixels with mask values which are  greater
than  zero  are not counted in the sample.  Only the first pixels up
to the limit are selected where the order is by line beginning  from
the  first line.  If no mask is specified then a grid of pixels with
even spacing along lines and columns that  make  up  a  number  less
than or equal to the maximum sample size is used.

If  a  contrast of zero is specified (or the zrange flag is used and
the image does not have a  valid  minimum/maximum  value)  then  the
minimum  and maximum of the sample is used for the intensity mapping
range.

If the contrast  is  not  zero  the  sample  pixels  are  ranked  in
brightness  to  form  the  function  I(i) where i is the rank of the
pixel and I is its value.  Generally the midpoint of  this  function
(the  median) is very near the peak of the image histogram and there
is a well defined slope about the midpoint which is related  to  the
width  of the histogram.  At the ends of the I(i) function there are
a few very bright and dark pixels due to objects and defects in  the
field.   To  determine  the  slope  a  linear  function  is fit with
iterative rejection;

<code>
        I(i) = intercept + slope * (i - midpoint)
</code>

If more than half of the points are rejected then there is  no  well
defined  slope  and  the full range of the sample defines z1 and z2.
Otherwise the endpoints of the linear function  are  used  (provided
they are within the original range of the sample):

<code>
        z1 = I(midpoint) + (slope / contrast) * (1 - midpoint)
        z2 = I(midpoint) + (slope / contrast) * (npoints - midpoint)
</code>

As  can  be  seen,  the parameter contrast may be used to adjust the
contrast produced by this algorithm.
Parameters
imageThe image we wish to stretch
nSamplesNumber of samples to use
contrastStretch parameter; see description

Definition at line 185 of file scaling.cc.

189 {
190  // extract samples
191  std::vector<T> vSample;
192  getSample(image, nSamples, vSample);
193  int nPix = vSample.size();
194 
195  if (vSample.empty()) {
196  throw LSST_EXCEPT(pex::exceptions::RuntimeError, "ZScale: No pixel in image is finite");
197  }
198 
199  std::sort(vSample.begin(), vSample.end());
200 
201  // max, min, median
202  // N.b. you can get a median in linear time, but we need the sorted array for fitLine()
203  // If we wanted to speed this up, the best option would be to quantize
204  // the pixel values and build a histogram
205  double const zmin = vSample.front();
206  double const zmax = vSample.back();
207  int const iCenter = nPix/2;
208  T median = (nPix & 1) ? vSample[iCenter] : (vSample[iCenter] + vSample[iCenter + 1])/2;
209 
210  // fit a line to the sorted sample
211  const int maxRejectionRatio = 2;
212  const int npixelsMin = 5;
213 
214  int minpix = std::max(npixelsMin, nPix/maxRejectionRatio);
215  int nGrow = std::max(1, nPix/100);
216 
217  const double nSigmaClip = 2.5;
218  const int nIterations = 5;
219 
220  int nGoodPix = 0;
221  std::pair<double, double> ret = fitLine(&nGoodPix, vSample, nSigmaClip, nGrow, minpix, nIterations);
222 #if 0 // unused, but calculated and potentially useful
223  double const zstart = ret.first;
224 #endif
225  double const zslope = ret.second;
226 
227  double z1, z2;
228  if (nGoodPix < minpix) {
229  z1 = zmin;
230  z2 = zmax;
231  } else {
232  double const slope = zslope/contrast;
233 
234  z1 = std::max(zmin, median - iCenter*slope);
235  z2 = std::min(zmax, median + (nPix - iCenter - 1)*slope);
236  }
237 
238  return std::make_pair(z1, z2);
239 }
#define LSST_EXCEPT(type,...)
Create an exception with a given type and message and optionally other arguments (dependent on the ty...
Definition: Exception.h:46
template std::pair<double, double> lsst::afw::display::getZScale ( image::Image< std::uint16_t > const &  image,
int const  nSamples,
double const  contrast 
)
template std::pair<double, double> lsst::afw::display::getZScale ( image::Image< float > const &  image,
int const  nSamples,
double const  contrast 
)
lsst::afw::display::if ( width!  = gim.getWidth() || height != gim.getHeight() || x0 != gim.getX0() || y0 != gim.getY0())

Definition at line 47 of file saturated.cc.

47  {
48  throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
49  str(boost::format("R image has different size/origin from G image "
50  "(%dx%d+%d+%d v. %dx%d+%d+%d") %
51  width % height % x0 % y0 %
52  gim.getWidth() % gim.getHeight() % gim.getX0() % gim.getY0()));
53 
54  }
int const x0
Definition: saturated.cc:45
void ImageT ImageT int float saturatedPixelValue int const width
Definition: saturated.cc:44
void ImageT ImageT int float saturatedPixelValue int const height
Definition: saturated.cc:44
#define LSST_EXCEPT(type,...)
Create an exception with a given type and message and optionally other arguments (dependent on the ty...
Definition: Exception.h:46
void ImageT & gim
Definition: Rgb.h:36
int const y0
Definition: saturated.cc:45
sat lsst::afw::display::merge ( detection::FootprintSet(*.  getMask,
satThresh  ,
npixMin   
)
template void lsst::afw::display::replaceSaturatedPixels ( image::MaskedImage< float > &  rim,
image::MaskedImage< float > &  gim,
image::MaskedImage< float > &  bim,
int  borderWidth,
float  saturatedPixelValue 
)
detection::FootprintSet sat * lsst::afw::display::rim ( )
template<typename ImageT >
void lsst::afw::display::writeBasicFits ( int  fd,
ImageT const &  data,
image::Wcs const *  Wcs,
char const *  title 
)

Definition at line 362 of file simpleFits.cc.

366  {
367  /*
368  * Allocate cards for FITS headers
369  */
370  std::list<Card> cards;
371  /*
372  * What sort if image is it?
373  */
374  int bitpix = lsst::afw::fits::getBitPix<typename ImageT::Pixel>();
375  if (bitpix == 20) { // cfitsio for "Unsigned short"
376  cards.push_back(Card("BZERO", 32768.0, ""));
377  cards.push_back(Card("BSCALE", 1.0, ""));
378  bitpix = 16;
379  } else if (bitpix == 0) {
380  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Unsupported image type");
381  }
382  /*
383  * Generate WcsA, pixel coordinates, allowing for X0 and Y0
384  */
385  std::string wcsName = "A";
386  cards.push_back(Card(str(boost::format("CRVAL1%s") % wcsName),
387  data.getX0(), "(output) Column pixel of Reference Pixel"));
388  cards.push_back(Card(str(boost::format("CRVAL2%s") % wcsName),
389  data.getY0(), "(output) Row pixel of Reference Pixel"));
390  cards.push_back(Card(str(boost::format("CRPIX1%s") % wcsName), 1.0,
391  "Column Pixel Coordinate of Reference"));
392  cards.push_back(Card(str(boost::format("CRPIX2%s") % wcsName), 1.0, "Row Pixel Coordinate of Reference"));
393  cards.push_back(Card(str(boost::format("CTYPE1%s") % wcsName), "LINEAR", "Type of projection"));
394  cards.push_back(Card(str(boost::format("CTYPE1%s") % wcsName), "LINEAR", "Type of projection"));
395  cards.push_back(Card(str(boost::format("CUNIT1%s") % wcsName), "PIXEL", "Column unit"));
396  cards.push_back(Card(str(boost::format("CUNIT2%s") % wcsName), "PIXEL", "Row unit"));
397  /*
398  * Now WcsB, so that pixel (0,0) is correctly labelled (but ignoring XY0)
399  */
400  wcsName = "B";
401  cards.push_back(Card(str(boost::format("CRVAL1%s") % wcsName), 0,
402  "(output) Column pixel of Reference Pixel"));
403  cards.push_back(Card(str(boost::format("CRVAL2%s") % wcsName), 0,
404  "(output) Row pixel of Reference Pixel"));
405  cards.push_back(Card(str(boost::format("CRPIX1%s") % wcsName), 1.0,
406  "Column Pixel Coordinate of Reference"));
407  cards.push_back(Card(str(boost::format("CRPIX2%s") % wcsName), 1.0, "Row Pixel Coordinate of Reference"));
408  cards.push_back(Card(str(boost::format("CTYPE1%s") % wcsName), "LINEAR", "Type of projection"));
409  cards.push_back(Card(str(boost::format("CTYPE1%s") % wcsName), "LINEAR", "Type of projection"));
410  cards.push_back(Card(str(boost::format("CUNIT1%s") % wcsName), "PIXEL", "Column unit"));
411  cards.push_back(Card(str(boost::format("CUNIT2%s") % wcsName), "PIXEL", "Row unit"));
412 
413  if (title) {
414  cards.push_back(Card("OBJECT", title, "Image being displayed"));
415  }
416  /*
417  * Was there something else?
418  */
419  if (Wcs != NULL) {
420  typedef std::vector<std::string> NameList;
421 
422  image::Wcs::Ptr newWcs = Wcs->clone(); //Create a copy
423  newWcs->shiftReferencePixel(-data.getX0(), -data.getY0());
424 
425  lsst::daf::base::PropertySet::Ptr metadata = newWcs->getFitsMetadata();
426 
427  NameList paramNames = metadata->paramNames();
428 
429  for (NameList::const_iterator i = paramNames.begin(), end = paramNames.end(); i != end; ++i) {
430  if (*i == "SIMPLE" ||
431  *i == "BITPIX" ||
432  *i == "NAXIS" ||
433  *i == "NAXIS1" ||
434  *i == "NAXIS2" ||
435  *i == "XTENSION" ||
436  *i == "PCOUNT" ||
437  *i == "GCOUNT"
438  ) {
439  continue;
440  }
441  std::type_info const &type = metadata->typeOf(*i);
442  if (type == typeid(bool)) {
443  cards.push_back(Card(*i, metadata->get<bool>(*i)));
444  } else if (type == typeid(int)) {
445  cards.push_back(Card(*i, metadata->get<int>(*i)));
446  } else if (type == typeid(float)) {
447  cards.push_back(Card(*i, metadata->get<float>(*i)));
448  } else if (type == typeid(double)) {
449  cards.push_back(Card(*i, metadata->get<double>(*i)));
450  } else {
451  cards.push_back(Card(*i, metadata->get<std::string>(*i)));
452  }
453  }
454  }
455  /*
456  * Basic FITS stuff
457  */
458  const int naxis = 2; // == NAXIS
459  int naxes[naxis]; /* values of NAXIS1 etc */
460  naxes[0] = data.getWidth();
461  naxes[1] = data.getHeight();
462 
463  write_fits_hdr(fd, bitpix, naxis, naxes, cards, 1);
464  for (int y = 0; y != data.getHeight(); ++y) {
465  if (write_fits_data(fd, bitpix, (char *)(data.row_begin(y)), (char *)(data.row_end(y))) < 0){
466  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
467  (boost::format("Error writing data for row %d") % y).str());
468  }
469  }
470 
471  pad_to_fits_record(fd, data.getWidth()*data.getHeight(), bitpix);
472 }
int y
Implementation of the WCS standard for a any projection.
Definition: Wcs.h:107
virtual Ptr clone(void) const
Definition: Wcs.cc:566
std::shared_ptr< Wcs > Ptr
Definition: Wcs.h:113
#define LSST_EXCEPT(type,...)
Create an exception with a given type and message and optionally other arguments (dependent on the ty...
Definition: Exception.h:46
std::shared_ptr< PropertySet > Ptr
Definition: PropertySet.h:85
template<typename ImageT >
void lsst::afw::display::writeBasicFits ( std::string const &  filename,
ImageT const &  data,
image::Wcs const *  Wcs,
char const *  title 
)

Definition at line 477 of file simpleFits.cc.

481  {
482  int fd;
483  if ((filename.c_str())[0] == '|') { // a command
484  const char *cmd = filename.c_str() + 1;
485  while (isspace(*cmd)) {
486  cmd++;
487  }
488 
489  fd = fileno(popen(cmd, "w"));
490  } else {
491  fd = creat(filename.c_str(), 777);
492  }
493 
494  if (fd < 0) {
495  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
496  (boost::format("Cannot open \"%s\"") % filename).str());
497  }
498 
499  try {
500  writeBasicFits(fd, data, Wcs, title);
502  (void)close(fd);
503  throw;
504  }
505 
506  (void)close(fd);
507 }
void writeBasicFits(int fd, ImageT const &data, image::Wcs const *Wcs, char const *title)
Definition: simpleFits.cc:362
Implementation of the WCS standard for a any projection.
Definition: Wcs.h:107
#define LSST_EXCEPT(type,...)
Create an exception with a given type and message and optionally other arguments (dependent on the ty...
Definition: Exception.h:46

Variable Documentation

template<typename ImageT >
void ImageT ImageT & lsst::afw::display::bim

Definition at line 36 of file Rgb.h.

template<typename ImageT >
void ImageT ImageT int lsst::afw::display::borderWidth = 2

Definition at line 38 of file Rgb.h.

boost::shared_ptr< FootprintList > lsst::afw::display.feet = sat.getFootprints()
Examples:
footprintFunctor.cc.

Definition at line 81 of file saturated.cc.

template<typename ImageT >
void ImageT & lsst::afw::display::gim

Definition at line 36 of file Rgb.h.

template<typename ImageT >
void ImageT ImageT int float saturatedPixelValue int const lsst::afw::display.height = rim.getHeight()

Definition at line 44 of file saturated.cc.

int const lsst::afw::display.npixMin = 1
Examples:
spatialCellExample.cc.

Definition at line 72 of file saturated.cc.

afw::image::MaskPixel const lsst::afw::display.SAT = rim.getMask()->getPlaneBitMask("SAT")

Definition at line 73 of file saturated.cc.

detection::Threshold const lsst::afw::display.satThresh(SAT, detection::Threshold::BITMASK)
template<typename ImageT >
void ImageT ImageT int float lsst::afw::display.saturatedPixelValue
Initial value:
= 65535
)

Definition at line 39 of file Rgb.h.

bool const lsst::afw::display.useMaxPixel = !std::isfinite(saturatedPixelValue)

Definition at line 64 of file saturated.cc.

template<typename ImageT >
void ImageT ImageT int float saturatedPixelValue int const lsst::afw::display.width = rim.getWidth()

Definition at line 44 of file saturated.cc.

int const lsst::afw::display.x0 = rim.getX0()
Examples:
imageStatistics.cc.

Definition at line 45 of file saturated.cc.

int const lsst::afw::display.y0 = rim.getY0()

Definition at line 45 of file saturated.cc.