Graphical tour of the bad value support in PDL
This demo is just a bit of eye-candy to show bad values in action, and requires PGPLOT support in PDL. It makes use of the image of m51 kindly provided by the Hubble Space Telescope.
It also serves to demonstrate that you often don't need to change your code to handle bad values, as the routines may 'do it' for you.
# read in the image ($m51path has been set up by this demo to # contain the location of the file) pdl> $m51 = rfits "$m51path/m51.fits"; # display it pdl> $just = { JUSTIFY => 1 }; pdl> imag $m51, $just; BITPIX = 16 size = 65536 pixels Reading 131072bytes BSCALE = 1.0000000000E0 && BZERO = 0.0000000000E0 Displaying 256 x 256 image from 24 to 500 ...
# now, let's mask out the central 30 pixels and display it
pdl> $masked = $m51->setbadif( $m51->rvals({CENTRE=>[128,128]}) < 30 );
# since imag auto-scales the output, the bad values are not displayed
pdl> imag $masked, $just;
# compare the statistics of the images
# (as $PDL::verbose = 1, stats prints out the answers itself)
pdl> print "Original:\n"; $m51->stats;
pdl> print "Masked:\n"; $masked->stats;
Displaying 256 x 256 image from 24 to 500 ...
Original: Mean = 104.193572998047, RMS = 67.4254208960541, Median = 88 Min = 24, Max = 500 Masked: Mean = 96.1637598444026, RMS = 49.9066302680633, Median = 86 Min = 24, Max = 500 # let's filter it a little bit pdl> use PDL::Image2D; pdl> $nb = 9; pdl> $filtered = med2d $masked, ones($nb,$nb), { Boundary => 'Truncate' }; # this is a model of the diffuse component of m51 pdl> imag $filtered, $just; Displaying 256 x 256 image from 38 to 313 ...
# unsharp masking, to bring out the small-scale detail
pdl> $unsharp = $masked - $filtered;
pdl> imag $unsharp, $just;
Displaying 256 x 256 image from -64 to 459 ...
# add on some contours showing the large scale structure of the galaxy
pdl> imag $unsharp, $just;
pdl> hold;
pdl> cont $filtered;
pdl> rel;
Displaying 256 x 256 image from -64 to 459 ...
Graphics on HOLD
Contouring 256 x 256 image from 38 to 313 in 9 steps
Graphics RELEASED