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)
perldl> $m51 = rfits "$m51path/m51.fits";
# display it
perldl> $just = { JUSTIFY => 1 };
perldl> 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
perldl> $masked = $m51->setbadif( $m51->rvals({CENTRE=>[128,128]}) < 30 );
# since imag auto-scales the output, the bad values are not displayed
perldl> imag $masked, $just;
# compare the statistics of the images
# (as $PDL::verbose = 1, stats prints out the answers itself)
perldl> print "Original:\n"; $m51->stats;
perldl> 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
perldl> use PDL::Image2D;
perldl> $nb = 9;
perldl> $filtered = med2d $masked, ones($nb,$nb), { Boundary => 'Truncate' };
# this is a model of the diffuse component of m51
perldl> imag $filtered, $just;
Displaying 256 x 256 image from 38 to 313 ...
# unsharp masking, to bring out the small-scale detail
perldl> $unsharp = $masked - $filtered;
perldl> imag $unsharp, $just;
Displaying 256 x 256 image from -64 to 459 ...
# add on some contours showing the large scale structure of the galaxy
perldl> imag $unsharp, $just;
perldl> hold;
perldl> cont $filtered;
perldl> 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
Last modified: Tuesday, 08-Apr-2008 10:32:36 PDT