|
A couple of illustrations on how to use the new functions. Let's see what TileJson is about. That is, let's create a new tile filled with a constant using TileMakeNew, then convert it into JSON using TileJson and look at the result. ? TileJson(TileMakeNew(3, 3, 1)) nvarchar: [ 1, 1, 1, 1, 1, 1, 1, 1, 1 ] Fine. Let's try to go the other direction: ? StringJsonTile('[ 1, 1, 1, 1, 1, 1, 1, 1, 1 ]', 3, 3, 1, true) tile: <tile, 3x3, float64> Seems to work. We had to tell the function the dimensions of the tile and the number of channels. Let's try changing some of the pixels and round-trip them: ? TileJson(StringJsonTile('[ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]', 3, 3, 1, true)) nvarchar: [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ] Good. Let's try filtering the last tile with blur: ? TileJson(TileFilter( StringJsonTile('[ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]', 3, 3, 1, true), 1, -- radius TileFilterDefBlur(1, 1))) -- radius and then center nvarchar: [ null, null, null, null, 5, null, null, null, null ] Border pixels are NULL = invisible. The center pixel remained at 5. Let's change the source tile slightly, creating a peak in the center: ? TileJson(TileFilter( StringJsonTile('[ 1, 1, 1, 1, 2, 1, 1, 1, 1 ]', 3, 3, 1, true), 1, TileFilterDefBlur(1, 1))) nvarchar: [ null, null, null, null, 1.1111111111111112, null, null, null, null ] The peak got averaged. Let's now create a slightly bigger tile and save it to stop typing the pixels: VALUE @t TILE = StringJsonTile( '[ 1, 1, 1, 1, 1,' + ' 2, 2, 3, 3, 2,' + ' 2, 3, 3, 3, null,' + -- last pixel in row invisible ' 1, 2, 1, 3, 2,' + ' 1, 1, 1, 4, 3 ]', 5, 5, 1, true); ...got an empty table as a result, but no errors. Let's try filtering the tile using Gaussian blur: ? TileJson(TileFilter(@t, 1, TileFilterDefBlurGaussian(1, 1))) nvarchar: [ null, null, null, null, null, null, 2.010513231195137, 2.9676335821954316, 2.967629759157991, null, null, 2.9675154787355518, 2.9785011237702075, 2.999522509802396, null, null, 1.9786192272300867, 1.0539833974942394, 2.97849858437863, null, null, null, null, null, null ] ...how does Gaussian blur work, by the way? Let's check: ? TileJson(TileFilterDefBlurGaussian(1, 1)) nvarchar: [ 0.00012340980408667956, 0.011108996538242306, 0.00012340980408667956, 0.011108996538242306, 1, 0.011108996538242306, 0.00012340980408667956, 0.011108996538242306, 0.00012340980408667956 ] OK. Each pixel gets contributions from surrounding pixels which decay fast with distance. Makes sense. Let's compute slope: ? TileJson(TileSlope(@t, 1, VectorMakeX3(1, 1, 1))) nvarchar: [ null, null, null, null, null, null, 41.90884788180326, 45.392449120640315, 45.392449120640315, null, null, 31.002719133873985, 25.239401820678918, 18.43494882292201, null, null, 40.35910045666124, 39.80557109226519, 27.791305644779218, null, null, null, null, null, null ] ...seems highest on the top edge of the tile where 1s change to 3s and low near the center. How does that change if we tell the function that the horizontal distance between pixels is 20 times bigger than whatever the Z units are? ? TileJson(TileSlope(@t, 1, VectorMakeX3(20, 20, 1))) nvarchar: [ null, null, null, null, null, null, 2.5695028228896355, 2.9018215173024653, 2.9018215173024653, null, null, 1.7210061534334906, 1.3502244696996157, 0.9548412538721887, null, null, 2.433138796850444, 2.385944030388813, 1.5095270002735288, null, null, null, null, null, null ] Slopes just got much smaller. By the way, this all was being computed on GPU because we didn't say anything to the query engine and by default it sends functions like TileSlope to GPU, if there is one. Let's check what the numbers are if we compute on CPU: PRAGMA ('gpgpu'='none'); ...and then: ? TileJson(TileSlope(@t, 1, VectorMakeX3(20, 20, 1))) nvarchar: [ null, null, null, null, null, null, 2.5695028228896355, 2.9018215173024653, 2.9018215173024653, null, null, 1.7210061534334908, 1.3502244696996157, 0.9548412538721887, null, null, 2.433138796850444, 2.385944030388813, 1.5095270002735288, null, null, null, null, null, null ] ...same as on GPU. Which is good. Let's try median filter. With a cross shape. On slope data. First switch back to GPU: PRAGMA ('gpgpu'='auto'); ...then: ? TileJson(TileFilterMedian( TileSlope(@t, 1, VectorMakeX3(20, 20, 1)), 2, -- radius TileFilterDefCross(1, 1))) nvarchar: [ null, null, null, null, null, null, 2.5695028228896355, 2.9018215173024653, 2.9018215173024653, null, null, 2.433138796850444, 1.7210061534334908, 1.5095270002735288, null, null, 2.385944030388813, 2.385944030388813, 1.5095270002735288, null, null, null, null, null, null ] Checking for the center pixel which got chosen as a median from itself plus the four pixels to the left / right / top / bottom = a median from { 2.901..., 1.721..., 1.350..., 0.954..., 2.385... } = 1.721... . Seems fine. Hope this helps.
|