#!/usr/local/bin/perl -w # Ashish Mahabal # 20 July 2007 # Converts fits 2 jpeg with sigma clipping # USAGE; $0 -in foo.fits [options] use strict; use Carp; use Getopt::Euclid; use PDL; use PDL::IO::Pic; ######################################### # Read in the arguments. No booleans currently. my $inimage=$ARGV{-inimage}; my $outimage=$ARGV{-outimage}; my $mask=$ARGV{-mask}; my $badtype=$ARGV{-badtype}; unless(defined $outimage){ my $root; ($root=$inimage)=~s/.fits$//; $outimage="$root.jpg"; print "outimage is $outimage\n"; } unless(defined $mask){ $mask="$inimage"; } # $badtype = 1 for swarped images (where 0 in mask is bad) and 0 for iraf images (where 1 in masks is bad) #unless(@ARGV == 4){print "USAGE: $0 fitsfile mask badtype jpeg\n";exit;} #my ($fits,$mask,$badtype,$jpg)=@ARGV; my $FITSPdl=rfits($inimage); my $MASKPdl=rfits($mask); my $bad = 1 - $badtype; #print "mean,stddev,median,min,max\n"; #print "Before setbad ",join(" ",stats($FITSPdl)),"\n"; #print "Mask ",join(" ",stats($MASKPdl)),"\n"; #$FITSPdl = $FITSPdl->setbadif( $MASKPdl == $bad ); #print "After setbad ",join(" ",stats($FITSPdl)),"\n"; my $q=$FITSPdl->flat->qsort; #($mean,$rms,$median,$min,$max) = stats($piddle,[$weights]); # rms is same as stddev #my ($mean,$stddev,$median,$min,$max)=$q->stats; my ($mean,$stddev,$median,$min,$max)=stats($FITSPdl,$MASKPdl); #print "comb stats: $mean,$stddev,$median,$min,$max\n"; my $totpix = $q->getdim(0); my $q75=$q->at(0.75*$totpix); my $q25=$q->at(0.25*$totpix); my $sigma=0.7415*($q75-$q25); my $white=$median-(1.5*$sigma); my $black=$median+(15*$sigma); my $tmpw=$FITSPdl->where($FITSPdl<$white); my $tmpb=$FITSPdl->where($FITSPdl>$black); $tmpw.=$white; $tmpb.=$black; #print "from black to white",join(" ",stats($FITSPdl)),"\n"; $FITSPdl=byte 255*($FITSPdl-$white)/($black-$white); #print "as bytes: ",join(" ",stats($FITSPdl)),"\n"; $FITSPdl->wpic("image.jpg"); system("overlay_circle.pl -in=image.jpg -out=$outimage"); unlink("image.jpg"); ############################################ __END__ =head1 NAME fits2jpg.pl - convert a fits image to jpeg with options =head1 VERSION version 0.1 =head1 USAGE fits2jpg.pl -inimage [options] =head1 REQUIRED ARGUMENTS =over =item -in[image] [=] Specify input image name =for Euclid: INIMAGE.type: string =back =head1 OPTIONS =over =item -out[image] [=] Specify output image name. Defaults to inimage with .fits replaced with .jpg =for Euclid: OUTIMAGE.type: string =item -mask [=] Specify mask image name. Defaults to inimage. =for Euclid: MASK.type: string =item -badtype [=] [integer] Badpixel type of the object. Defaults to 1. For swarped images it should be 1. For iraf images it should be 0. Does not matter if separate mask is not provided. =for Euclid: badtype.type: integer badtype.default: 1 =item -v =item --verbose Print all warnings =item --version =item --usage =item --help =item --man Print the usual program information =back =head1 AUTHOR Ashish Mahabal =head1 BUGS There are undoubtedly serious bugs lurking somewhere in this code. Bug reports and other feedback are most welcome. =head1 COPYRIGHT Copyright (c) 2007, Ashish Mahabal. All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the terms of the Perl Artistic License (see http://www.perl.com/perl/misc/Artistic.html)