FME Version
Files
Introduction
An edge in a raster dataset is where the intensity of the values changes abruptly. Edges generally occur at the boundary of areas or objects, and so (for spatial data) are useful for extracting important features such as the edge of an area of vegetation.
Edges can be detected in FME with the RasterConvolver transformer, using a process called Convolution.
Convolution is a mathematical operation carried out between a raster feature and a matrix of numbers (a kernel). The definition of operation and kernel is often called a filter.
Edge Direction
The "direction" of an edge is from the low intensity part towards the high intensity part. Edges can occur in either a primarily vertical or horizontal orientation. Therefore the RasterConvolver allows the user to detect edges from left to right, right to left, top to bottom, or bottom to top.
Where the raster has a mix of edge directions, or where the primary edge direction is not known, it's possible to detect edges in all four directions, and to merge them together with an ExpressionEvaluator. This example uses that technique.
Source Data
The source data for these examples is a Raster image dataset in JPEG format. In the FME Data Inspector it looks like this:
The image is an aerial view of an area of Vancouver containing a school. Let's say that for this exercise we wish to identify the different surfaces and buildings on the school grounds.
Step-By-Step Instructions
1. Start FME Workbench and open the starting template file provided. This workspace reads the image data and a rough outline of the school property, which it uses to clip the image to size:
Turn on feature caching in Workbench (Run > Run with Feature Caching) and run the workspace. Inspect the clipped result:
2. Add a RasterConvolver transformer connected to the Clipper:Inside port. Open the parameters dialog to inspect the different filter types. Notice that there are four edge detection filters called Sobel:
Select Sobel Top and click OK to close the parameters dialog. Run the workspace (or just this part of it) and inspect the output. Notice that edges are being detected.
However, there are three other Sobel edge detection filters, and we should also try these out.
3. Add three more RasterConvolver transformers. Connect each of them to a new connection from the Clipper:Inside port:
Set each of them to use a different Sobel filter: Sobel Top, Sobel Bottom, Sobel Left, Sobel Right.
Run the workspace (select the RasterConvolver transformers and press F6). Inspect the output (select the RasterConvolver transformers and press Ctrl+I).
Notice that each type of filter adds information about edges viewed from a different direction. To get a complete result we should merge these together.
4. Place a RasterExpressionEvaluator transformer on the canvas and, without connecting to anything else, open up the parameters dialog.
Set the Mode parameter to Two Rasters:
In the Band Expression(s) field, set the first Interpretation to Red8. In the Expression field enter:
@sqrt((A[0]*A[0]) + (B[0]*B[0]))
In other words we are combining band zero of the two raster features together. The new value for each cell will be the square root of Raster A's value (squared) plus Raster B's value (squared).
Repeat the process for bands one and two (Green8 and Blue8), changing the band number in the expression each time:
@sqrt((A[1]*A[1]) + (B[1]*B[1])) @sqrt((A[2]*A[2]) + (B[2]*B[2]))
Now close the parameter dialog and connect the first two RasterConvolver outputs to the A and B input ports on the RasterExpressionEvaluator:
Notice that the RasterExpressionEvaluator does not allow all four rasters to be processed at once; therefore we need to use multiple transformers.
5. Duplicate the existing RasterExpressionEvaluator (either copy/paste or Ctrl+D). Connect it to the second set of RasterConvolver:Output ports. Because the expression is exactly the same the parameters do not need to be changed.
Now duplicate one of the RasterExpressionEvaluators for a second time. This time connect it to the Result ports of the existing RasterExpressionEvaluators:
Now run the workspace and inspect the result of the third RasterExpressionEvaluator:
We can see the edges of the surfaces and buildings, but there is a fair amount of noise in the image too.
6. Add a RasterConvolver transformer between the Clipper and each of the existing RasterConvolver transformers (for Quick Add click on the green output port arrow on the Clipper before typing the RasterConvolver name):
Open the parameters dialog and set the Convolution Filter type to Blur: Gaussian 5
Re-run the workspace and inspect the final output once more. Although the edges of the surfaces are a little fuzzier, there is far less noise in the image.
Optional Steps
7. If you would prefer a white image with black outlines (instead of black with white outlines) then open the parameters dialog for the final RasterExpressionEvaluator. Change the expressions to:
255-(@sqrt((A[0]*A[0]) + (B[0]*B[0]))) 255-(@sqrt((A[1]*A[1]) + (B[1]*B[1]))) 255-(@sqrt((A[2]*A[2]) + (B[2]*B[2])))
For an 8-bit raster, 255 minus the value gives an inverted image.
You may also add a RasterInterpretationCoercer transformer to the end of the workspace to make the color a standard grey. Set the option for "Destination Interpretation Type" to Gray8 and the option for "Convert Color to Color" to Cast.
Re-run the workspace. The final output will now be black lines on a white background:
You can now use these outlines (in either a manual or automated process) to determine the surfaces and buildings on the school property.
Cautions
The quality of the results depends very much on the image having clear and well-defined boundaries, between areas that differ greatly in intensity.
For example here the user attempts to define the edges of containers sitting on a dock:
Unfortunately, the edges with the most intensity differences are the container shadows; therefore the shadows have the clearest edge definition while the containers are hidden against the background surface.
Comments
0 comments
Please sign in to leave a comment.