Friday, May 22, 2009

Fill Holes and Slivers in Imagery (Single Value)

Here is a graphic Spatial Model (PaulBeaty_HoleFiller.gmd) I created when I was at Georgia Tech. It fills DEM and other raster data (including imagery) holes and slivers with data calculated values from surrounding pixel values. These 1, 2 and sometimes 3 pixel wide artifacts are common to users who have reprojected butt-matched raster data. This model finds the "to-be-replaced" value and determines whether a 3 x 3 or 5 x 5 focal mean should be applied. The model ignores the replacement value when calculating the focal mean.

Copy and paste the text below into a text editor and save as ANSI text file without the text editor's formatting. Save as PaulBeaty_HoleFiller.gmd and open in Model Maker.

PAGESIZE 6.04444, 8.83889 INCHES;
CELLSIZE MINIMUM;
PRINTERPAGESIZE 8.5, 11;
MARGINS 0.5, 0.5, 0.5, 0.5;
ORIENTATION PORTRAIT;
PRINTSCALE 100;
WINDOW INTERSECTION;
PROJECTION DEFAULT;
AOI NONE;
OPTIMIZE YES;
RASTER {
ID 1;
TITLE "n1_PROMPT_USER";
POSITION 0.8, 1.7;
PROMPT;
INTERPOLATION NEAREST;
ATHEMATIC;
DATATYPE SIGNED16;
DECLARE "Integer";
COMPRESSION UNCOMPRESSED;
COORDINATES MAP;
AOI NONE;
RECODE NO;
CHILD 2;
}
FUNCTION {
ID 2;
TITLE "EITHER";
POSITION 2, 3.3;
VALUE "EITHER (FOCAL MEAN ( $n1_PROMPT_USER , $n6_Low_Pass , IGNORE_VALUE $n5_Integer , APPLY_AT_VALUE $n5_Integer ) ) IF ( (FOCAL MAJORITY ( $n1_PROMPT_USER , $n3_Low_Pass ) == $n5_Integer) ) OR (FOCAL MEAN ( $n1_PROMPT_USER , $n3_Low_Pass , IGNORE_VALUE $n5_Integer , APPLY_AT_VALUE $n5_Integer ) ) OTHERWISE";
AREA UNION;
CHILD 4;
}
MATRIX {
ID 3;
TITLE "n3_Low_Pass";
POSITION 3.3, 5.9;
SIZE 3, 3;
DATATYPE SIGNED32;
BUILTIN LOWPASS;
VALUE 1, 1, 1,
1, 1, 1,
1, 1, 1;
NORMALIZE NO;
CHILD 2;
}
RASTER {
ID 4;
TITLE "n4_PROMPT_USER";
POSITION 0.988889, 5.5;
PROMPT;
NEWFILE;
INTERPOLATION NEAREST;
ATHEMATIC;
DATATYPE SIGNED16;
DECLARE "Integer";
COMPRESSION UNCOMPRESSED;
COORDINATES MAP;
RECODE NO;
}
SCALAR {
ID 5;
TITLE "n5_Integer";
POSITION 0.6, 4;
DATATYPE SIGNED32;
VALUE -32767;
SHOW;
CHILD 2;
}
MATRIX {
ID 6;
TITLE "n6_Low_Pass";
POSITION 3.2, 1.8;
SIZE 5, 5;
DATATYPE SIGNED32;
BUILTIN LOWPASS;
VALUE 1, 1, 1, 1, 1,
1, 1, 1, 1, 1,
1, 1, 1, 1, 1,
1, 1, 1, 1, 1,
1, 1, 1, 1, 1;
NORMALIZE NO;
CHILD 2;
}
TEXT {
ID 7;
TITLE "Repair DEM Holes and Slivers";
POSITION 2.4, 0.5;
FONT "new century schoolbook";
SIZE 18;
}
TEXT {
ID 8;
TITLE "5 x 5 filter";
POSITION 3.2, 1.1;
FONT "new century schoolbook";
SIZE 12;
}
TEXT {
ID 10;
TITLE "Value to Replace";
POSITION 0.644444, 3.4;
FONT "new century schoolbook";
SIZE 12;
}
TEXT {
ID 11;
TITLE "3 x 3 filter";
POSITION 3.4, 5.2;
FONT "new century schoolbook";
SIZE 12;
}
TEXT {
ID 13;
TITLE "Conditional statement to determine";
POSITION 3.7, 2.8;
FONT "new century schoolbook";
SIZE 10;
}
TEXT {
ID 14;
TITLE "which filter is appropriate. If a majority";
POSITION 3.8, 3;
FONT "new century schoolbook";
SIZE 10;
}
TEXT {
ID 15;
TITLE "of the pixels are the \"Value to Replace,\"";
POSITION 3.83333, 3.18889;
FONT "new century schoolbook";
SIZE 10;
}
TEXT {
ID 16;
TITLE "the 5 x 5 filter is used. Otherwise, ";
POSITION 3.7, 3.4;
FONT "new century schoolbook";
SIZE 10;
}
TEXT {
ID 17;
TITLE "the 3 x 3 filter is used.";
POSITION 3.3, 3.6;
FONT "new century schoolbook";
SIZE 10;
}
TEXT {
ID 18;
TITLE "Be sure to define the correct";
POSITION 1.2, 6.4;
FONT "new century schoolbook";
SIZE 10;
}
TEXT {
ID 19;
TITLE "\"Data Type\" in the output file.";
POSITION 1.2, 6.6;
FONT "new century schoolbook";
SIZE 10;
}
TEXT {
ID 20;
TITLE "Created in IMAGINE 8.4 - Developed by Paul Beaty";
POSITION 2.7, 7.4;
FONT "new century schoolbook";
SIZE 10;
}
TEXT {
ID 21;
TITLE "Center for Geographic Information Systems";
POSITION 2.7, 7.6;
FONT "new century schoolbook";
SIZE 10;
}
TEXT {
ID 22;
TITLE "Georgia Institute of Technology - Atlanta Georgia, USA";
POSITION 2.8, 7.8;
FONT "new century schoolbook";
SIZE 10;
}
TEXT {
ID 26;
TITLE "Both filters ignore the \"Value to Replace\"";
POSITION 3.9, 3.8;
FONT "new century schoolbook";
SIZE 10;
}
TEXT {
ID 27;
TITLE "when calculating the mean.";
POSITION 3.48889, 4;
FONT "new century schoolbook";
SIZE 10;
}


No comments: