Index Out Of Range and Logic in Wave arithmatic
deconite
I've traditionally done this kind of thing in a nested for-loop, where I'll check each element index by index, and if I find a NaN, I'll replace that with a neighboring value (our imaging resolution is lower than our pixel size).
This is slow. So I'm trying to replace it with this line of code:
TheTrap[][] = (TheTrap(p)(q)!=NaN)*TheTrap(p)(q) +(TheTrap(p)(q)==NaN && p>0)*TheTrap(p-1)(q) +(TheTrap(p)(q)==NaN && p==0)*TheTrap(p+1)(q)
The first bit returns the original image if it has a finite value. The second bit replaces any NaNs found with the value of the pixel to the left if there exists a pixel to the left. And the final bit replaces any NaNs found on the leftmost part of the image with the value of the pixel immediately to the right.
What I get when I run is an "index is out of range" message, because in the second bit the program is ostensibly trying to multiply 0*TheTrap(-1)(q). Is there a way to get around this without resorting to a for loop?
2) How about MatrixFilter NaNZapMedian?
3) Use a subrange to limit the left-hand side:
Variable cols = DimSize(TheTrap, 1)
TheTrap[1,rows-1][1,cols-1] = ...
TheTrap[0][1,cols-1] = ...
etc.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
June 19, 2014 at 03:05 pm - Permalink
Wave w
w[][] = numtype(w[p][q])==0 ? w[p][q] : w[p-1+2*(p==0)][q]
End
Also note that when the leftmost (p=0) AND the adjacent pixel to the right (p+1) contain NaNs the function is unable to overwrite these.
June 19, 2014 at 07:18 pm - Permalink
And MatrixFilter documentation claims that NaNZapMedian "automatically cycles through matrix until all NaNs are gone".
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
June 20, 2014 at 08:52 am - Permalink
June 20, 2014 at 02:02 pm - Permalink