computing the standard deviation of pixels above zero

I have an HDR image that was generated by combining the original HDR with
an equally sized bitmap image to mask out an area within the image for
analysis. I have a script that enables the average luminance of the masked
area to be computed via (from the below script):

taskavg=`thpic -o $inp $tdir/$task.pic | toflt | total -if`

*I would like to compute the standard deviation of only the non-zero
pixels and am unsure how to do this.

the program "total" has a number of options to calculate the mean, max,
min, RMS,etc, but i need to filter out all of the zero'ed pixels before/as
I pass the pixel data to it.

Any suggestions would be appreciated. I have put a sample image (out.hdr)
as well as the script, mask, and orig image (example.hdr) in the following
directory online

https://gaia.lbl.gov/people/kskonis/share/TEMP/masks_lab/

best,

Kyle Konis
Ph.D Student
UC Berkeley / LBNL

ยทยทยท

################################
#!/bin/csh -f
# modified from "analyz.csh" 2005

# used to apply the mask and return an image with all pixels black,
# except the un-masked pixels
alias thpic 'pcomb -e "lo=if(gi(2)-.5,li(1),0)" \!*'

# -h -H do not print header or resolution string
# -pG print only the primary GREEN
# -df Output [binary 32-bit float values]
alias toflt 'pvalue -h -H -pG -df \!*'

set task=task
set mdir=/Users/kyle/HDR/masks_lab/masks
set tdir=/tmp/anl71t$$
mkdir $tdir

# convert picture [from] Windows BMP image to RADIANCE
# -r from a Windows BMP image to a RADIANCE picture
ra_bmp -r $mdir/$task.bmp $tdir/$task.pic

toflt $tdir/$task.pic | total -if > $tdir/$task.tot

set taskarea=`cat $tdir/$task.tot`
echo "task area is" $taskarea

set inp = *.hdr
echo "input image is" $inp
set taskavg=`thpic -o $inp $tdir/$task.pic | toflt | total -if`

echo "task average is" $taskavg
set taskavg=`ev "179*$taskavg/$taskarea"`
echo "task average is now" $taskavg

#output the masked image
thpic -o $inp $tdir/$task.pic > out.hdr