---------- Forwarded message ---------- From: Schregle Roland HSLU T&A <[email protected]> Date: Thu, Mar 13, 2014 at 10:27 AM Subject: Re: [Perldl] Implementing sigma clipping on RGB image stack
On Tue, 11 Mar 2014 23:28:20 +0100, Chris Marshall <[email protected]> wrote: > Hi Roland- > > It looks like you've already gotten everything working but > the final selective average. I've put comments inline with > your text below on ways I would do things for efficiency if > performance (speed or memory) were important. Hi Chris, Looks like I'm stuck again... ;^) The script does indeed seem to spend significant time glueing the images to the stack. I mucked about with accumulating the images in a fixed chunk pdl which is then cat'ed to the image stack; not only didn't this improve performance noticeably, it even ran out of memory! Instead I'm now simply pre-allocating the image stack once for a (user specified) maximum number of iterations, albeit using floats instead of doubles to conserve memory. Inserting the images into the stack using slicing works (and noticeably faster too), but triggers the nasty "Can't return a temporary from lvalue subroutine" error while debugging. While the documented workaround with temporary assignment suppresses this, it fails to update the image stack! Sample code follows: my $imgStack = float zeroes($imgComb -> dims, $maxIter); ... for (my $n = 0; $n <= $#imgFiles; $n++) { # Read image from file and add to image stack (with bogus # assignment as workaround for debugger!) my $imgSlice = ($imgStack -> slice(",,,$i-$n-1")); $imgSlice .= ReadImg($imgFiles [$n]); } Note that $i is the iteration counter, which points to the last completed iteration. @imgFiles contains the image filenames generated in the current chunk. I was under the impression assignments to slices always propagate back to their parent pdls, so I don't see why this doesn't work. Note that I have to rely on the debugger at this stage to figure ANYTHING out, so I'd prefer to keep this workaround at the expense of readability. On another note, I tried Craig's selective averaging using badvalue(), which worked with monochrome output, but I botched something up when adding on the extra dimension for RGB. I'll look into that later. One pitfall of sigma clipping is that it'll return zero for pixels whose values ALL deviate outside the threshold, i.e. are all bad. Predictably, this leaves ugly black holes in the averaged images. I figure in those cases it makes sense to simply drop in the single value which is closest to the median. How would I go about that? For starters, I'd get a mask of those averaged pixels which are still zero, multiply it by some selection which minimises the deviation from the mean and add it to the combined image (which should only update the zero elements). Something like: $zeroMask = (!$imgComb); $imgComb += zeroMask * where($hdrStack, min($imgStackDiff) -> dummy(0,3)) Haven't tried this yet. Sounds plausible? Sorry for nagging again, would appreciate a few hints to point me in the right direction. Thanks & best regards, --Roland -- Dr. Roland Schregle Senior Research Associate T direct: +41 41 349 39 77 [email protected] Lucerne University of Applied Sciences and Arts School of Engineering and Architecture CC Envelopes and Solar Energy (EASE) Technikumstrasse 21, CH-6048 Horw T +41 41 349 33 11, F +41 41 349 39 60 www.hslu.ch/ccease _______________________________________________ Perldl mailing list [email protected] http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
