Changeset: ec33a0dcbbe3 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ec33a0dcbbe3
Modified Files:
sql/test/sciql/Tests/teleios_noa_bsm.sql
Branch: sciql
Log Message:
teleios_noa_bsm: finished first complete & (hopefully) correct implementation
also cleaned-up code
diffs (truncated from 575 to 300 lines):
diff --git a/sql/test/sciql/Tests/teleios_noa_bsm.sql
b/sql/test/sciql/Tests/teleios_noa_bsm.sql
--- a/sql/test/sciql/Tests/teleios_noa_bsm.sql
+++ b/sql/test/sciql/Tests/teleios_noa_bsm.sql
@@ -10,15 +10,10 @@ DECLARE ndviThreshold DOUBLE;
SET ndviThreshold = 0; -- what is the correct value ?
--- implementation --
+-- loading data (images) --
-DECLARE d1 INT, d2 INT, majority INT;
-SET d1 = window_size / 2;
-SET d2 = d1 + 1;
-SET majority = (window_size * window_size) / 2;
-
--- Assuming these example TIF images are stored in /tmp
--- The orthorectified images need the GDAL functions attach2() and import2()
+---- Assuming these example TIF images are stored in /tmp
+---- The orthorectified images need the GDAL functions attach2() and import2()
CALL rs.attach2('/tmp/img1_b3.tif');
CALL rs.attach2('/tmp/img1_b4.tif');
CALL rs.attach2('/tmp/img1_b7.tif');
@@ -34,17 +29,31 @@ CALL rs.import2(3);
CALL rs.import2(4);
CALL rs.import2(5);
CALL rs.import2(6);
--- Now the TIF images have been imported as the following:
--- the b3, b4 and b7 of the 1st image as rs.image1, rs.image2 and rs.image3
--- the b3, b4 and b7 of the 2nd image as rs.image4, rs.image5 and rs.image6
+---- Now the TIF images have been imported as the following:
+---- b3, b4 and b7 of the 1st image as rs.image1, rs.image2 and rs.image3
+---- b3, b4 and b7 of the 2nd image as rs.image4, rs.image5 and rs.image6
+
+
+-- global variables and array --
+
+DECLARE d1 INT, d2 INT, majority INT;
+SET d1 = window_size / 2;
+SET d2 = d1 + 1;
+SET majority = (window_size * window_size) / 2;
DECLARE size_x INT, size_y INT;
SET size_x = (SELECT MAX(x) + 1 FROM rs.image1);
SET size_y = (SELECT MAX(y) + 1 FROM rs.image1);
--- BSM classification (landsatFirePredicate()) using one image
-CREATE ARRAY fire_1 (x INT DIMENSION[size_x], y INT DIMENSION[size_y], f INT);
-INSERT INTO fire_1 (
+CREATE ARRAY fire (x INT DIMENSION[size_x], y INT DIMENSION[size_y], f INT);
+
+
+-- BSM classification (landsatFirePredicate()) --
+
+--- two versions; please choose one:
+
+---- version 1: using one image
+INSERT INTO fire (
SELECT b3.x, b3.y, 1
FROM rs.image1 AS b3, rs.image2 AS b4, rs.image3 AS b7
WHERE b3.x = b4.x AND b3.y = b4.y AND b3.x = b7.x AND b3.y = b7.y -- join
the images
@@ -55,9 +64,8 @@ INSERT INTO fire_1 (
AND (CAST(b4.intensity-b7.intensity AS DOUBLE)/(b4.intensity +
b7.intensity) + 1.0) * 127.5 <= 126.0 -- indexNBR, 255.0/2.0=127.5
);
--- BSM classification (landsatFirePredicate()) using two images
-CREATE ARRAY fire_2 (x INT DIMENSION[size_x], y INT DIMENSION[size_y], f INT);
-INSERT INTO fire_2 (
+---- version 2: using two images
+INSERT INTO fire (
SELECT img1_b3.x, img1_b3.y, 1
FROM rs.image1 AS img1_b3, rs.image2 AS img1_b4, rs.image3 AS img1_b7,
rs.image4 AS img2_b3, rs.image5 AS img2_b4
@@ -75,292 +83,255 @@ INSERT INTO fire_2 (
CAST(img2_b4.intensity-img2_b3.intensity AS
DOUBLE)/(img2_b4.intensity + img2_b3.intensity) ) > ndviThreshold
);
--- BSM majority filter
----- should be:
-INSERT INTO fire_1 (
- SELECT [x], [y], 1
- FROM fire_1
- GROUP BY fire_1[x-d1:x+d2][y-d1:y+d2]
- HAVING f IS NULL AND SUM(f) > majority
-);
-INSERT INTO fire_2 (
- SELECT [x], [y], 1
- FROM fire_2
- GROUP BY fire_2[x-d1:x+d2][y-d1:y+d2]
- HAVING f IS NULL AND SUM(f) > majority
-);
+-- BSM majority filter --
----- however, the conjunctive HAVING clause yields wrong results;
----- hence:
+---- SHOULD be:
+--INSERT INTO fire (
+-- SELECT [x], [y], 1
+-- FROM fire
+-- GROUP BY fire[x-d1:x+d2][y-d1:y+d2]
+-- HAVING f IS NULL AND SUM(f) > majority
+--);
+---- HOWEVER, conjunctive HAVING clauses appear to YIELD WRONG RESULTS !??
-INSERT INTO fire_1 (
+---- hence, we need to avoid conjunctive HAVING clauses (for now?)
+INSERT INTO fire (
SELECT [x], [y], 1
FROM [
SELECT [x], [y], f
- FROM fire_1
- GROUP BY fire_1[x-d1:x+d2][y-d1:y+d2]
+ FROM fire
+ GROUP BY fire[x-d1:x+d2][y-d1:y+d2]
HAVING SUM(f) > majority
] AS tmp
WHERE f IS NULL
);
-INSERT INTO fire_2 (
- SELECT [x], [y], 1
- FROM [
- SELECT [x], [y], f
- FROM fire_2
- GROUP BY fire_2[x-d1:x+d2][y-d1:y+d2]
- HAVING SUM(f) > majority
- ] AS tmp
- WHERE f IS NULL
-);
--- BSM clump&eliminate filter
+-- BSM clump&eliminate filter --
+
---- initialize with distinct group ID per pixel
-UPDATE fire_1 SET f = x * size_y + y WHERE f IS NOT NULL;
-UPDATE fire_2 SET f = x * size_y + y WHERE f IS NOT NULL;
+UPDATE fire SET f = x * size_y + y WHERE f IS NOT NULL;
----- Clump adjacent pixels using 4-connected, i.e., each pixel has 8 neighbors,
----- namely N, NE, E, SE, S, SW, W, NW.
-CREATE FUNCTION clump_4connected_1()
+--- two versions; please choose one:
+--- CAVEAT: these take more than 30 minutes to execute !
+
+---- version 1:
+---- Clump adjacent pixels using 4-connected,
+---- i.e., each pixel has 4 neighbors: N, E, S, W
+---- HOWEVER, this DOES NOT WORK (yet?), as the SciQL implementation does
+---- not support structural grouping (tiling) with non-rectangular windows
+---- (tiles) (yet?) !??
+--CREATE FUNCTION clump_4connected()
+--RETURNS INT
+--BEGIN
+-- DECLARE iterations INT;
+-- SET iterations = 0;
+-- DECLARE moreupdates INT;
+-- SET moreupdates = 1;
+-- WHILE moreupdates > 0 DO
+-- SET iterations = iterations + 1;
+-- INSERT INTO fire (
+-- SELECT [x], [y], MAX(f)
+-- FROM fire AS a
+-- -- the SciQL implementation does not support this GROUP BY (yet?) !??
+-- GROUP BY a[x][y], a[x+1][y], a[x][y+1], a[x-1][y], a[x][y-1]
+-- HAVING f IS NOT NULL
+-- );
+-- SELECT SUM(res) INTO moreupdates
+-- FROM (
+-- SELECT MAX(f) - MIN(f) AS res
+-- FROM fire AS a
+-- -- the SciQL implementation does not support this GROUP BY (yet?) !??
+-- GROUP BY a[x][y], a[x+1][y], a[x][y+1], a[x-1][y], a[x][y-1]
+-- HAVING f IS NOT NULL
+-- ) AS updates;
+-- END WHILE;
+-- RETURN iterations;
+--END;
+--SELECT clump_4connected();
+
+---- version 2:
+---- Clump adjacent pixels using 8-connected,
+---- i.e., each pixel has 8 neighbors: N, NE, E, SE, S, SW, W, NW
+CREATE FUNCTION clump_8connected()
RETURNS INT
BEGIN
DECLARE iterations INT;
SET iterations = 0;
DECLARE moreupdates INT;
SET moreupdates = 1;
-
WHILE moreupdates > 0 DO
SET iterations = iterations + 1;
- INSERT INTO fire_1 (
+ INSERT INTO fire (
SELECT [x], [y], MAX(f)
- FROM fire_1 AS a
- -- the SciQL implementation does not seem to support this GROUP BY
(yet?) !?
- GROUP BY a[x][y], a[x+1][y], a[x][y+1], a[x-1][y], a[x][y-1]
+ FROM fire
+ GROUP BY fire[x-1:x+2][y-1:y+2]
HAVING f IS NOT NULL
);
- SELECT SUM(res) into moreupdates
+ SELECT SUM(res) INTO moreupdates
FROM (
SELECT MAX(f) - MIN(f) AS res
- FROM fire_1 AS a
- -- the SciQL implementation does not seem to support this GROUP BY
(yet?) !?
- GROUP BY a[x][y], a[x+1][y], a[x][y+1], a[x-1][y], a[x][y-1]
+ FROM fire
+ GROUP BY fire[x-1:x+2][y-1:y+2]
HAVING f IS NOT NULL
) AS updates;
END WHILE;
-
RETURN iterations;
END;
-
-CREATE FUNCTION clump_4connected_2()
-RETURNS INT
-BEGIN
- DECLARE iterations INT;
- SET iterations = 0;
- DECLARE moreupdates INT;
- SET moreupdates = 1;
-
- WHILE moreupdates > 0 DO
- SET iterations = iterations + 1;
- INSERT INTO fire_2 (
- SELECT [x], [y], MAX(f)
- FROM fire_2 AS a
- -- the SciQL implementation does not seem to support this GROUP BY
(yet?) !?
- GROUP BY a[x][y], a[x+1][y], a[x][y+1], a[x-1][y], a[x][y-1]
- HAVING f IS NOT NULL
- );
- SELECT SUM(res) into moreupdates
- FROM (
- SELECT MAX(f) - MIN(f) AS res
- FROM fire_2 AS a
- -- the SciQL implementation does not seem to support this GROUP BY
(yet?) !?
- GROUP BY a[x][y], a[x+1][y], a[x][y+1], a[x-1][y], a[x][y-1]
- HAVING f IS NOT NULL
- ) AS updates;
- END WHILE;
-
- RETURN iterations;
-END;
-
-select clump_4connected_1();
-select clump_4connected_2();
-
----- Clump adjacent pixels using 8-connected, i.e., each pixel has 8 neighbors,
----- namely N, NE, E, SE, S, SW, W, NW.
-CREATE FUNCTION clump_8connected_1()
-RETURNS INT
-BEGIN
- DECLARE iterations INT;
- SET iterations = 0;
- DECLARE moreupdates INT;
- SET moreupdates = 1;
-
- WHILE moreupdates > 0 DO
- SET iterations = iterations + 1;
- INSERT INTO fire_1 (
- SELECT [x], [y], MAX(f)
- FROM fire_1
- GROUP BY fire_1[x-1:x+2][y-1:y+2]
- HAVING f IS NOT NULL
- );
- SELECT SUM(res) into moreupdates
- FROM (
- SELECT MAX(f) - MIN(f) AS res
- FROM fire_1
- GROUP BY fire_1[x-1:x+2][y-1:y+2]
- HAVING f IS NOT NULL
- ) AS updates;
- END WHILE;
-
- RETURN iterations;
-END;
-
-CREATE FUNCTION clump_8connected_2()
-RETURNS INT
-BEGIN
- DECLARE iterations INT;
- SET iterations = 0;
- DECLARE moreupdates INT;
- SET moreupdates = 1;
-
- WHILE moreupdates > 0 DO
- SET iterations = iterations + 1;
- INSERT INTO fire_2 (
- SELECT [x], [y], MAX(f)
- FROM fire_2
- GROUP BY fire_2[x-1:x+2][y-1:y+2]
- HAVING f IS NOT NULL
- );
- SELECT SUM(res) into moreupdates
- FROM (
- SELECT MAX(f) - MIN(f) AS res
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list