Question

Raster erode/dilate


Badge

Hi,

I was wondering whether some basic operators like erode or dilate exist for raster processing? These operators enable opening and closing operation on raster, operations that are very useful.

Thanks for your answer,

Florian


16 replies

Userlevel 4
Badge +25

FME does not offer those options out of the box but depending on what you want to do the RasterExpressionEvaluator (for example) could be useful. I doubt it'll be able to do erode and dilate though.

Pinging @dmitribagh as he might have some suggestions for you.

Badge +16

Yes the RasterMaster himself @dmitribagh, is probably the only one that might help you out...

Badge +22

Sadly FME does not offer any focal analysis tools for raster. I use the command line of ImageMagick

What I do is write a temporary raster (FeatureWriter), use the SystemCaller to run the ImageMagick command(s) and then read the processed file back in with a FeatureReader.

Badge +22

Sadly FME does not offer any focal analysis tools for raster. I use the command line of ImageMagick

What I do is write a temporary raster (FeatureWriter), use the SystemCaller to run the ImageMagick command(s) and then read the processed file back in with a FeatureReader.

For a more "spatial aware" tool, I would look into Orfeo Toolbox. - I haven't used it myself yet, but it seems quite promissing.

 

 

Badge

Thanks jdh for your answer. As I am controlling the whole process with Python scripts I was about to make a workaround using OpenCV python library.

 

However, I will take a look at ImageMagick if the upper library is not fast enough.

Concerning the georeferencing, it could be a problem in case the erosion and/or dilation add pixel at the top or left borders, thus changing the world file. I am now not clear about how the dilating algorithm works in openCV and maybe one can specify to keep number of row and column.

Is the Orfeo Toolbox a ImageMagick plugin/derivate ?

Badge +22

Thanks jdh for your answer. As I am controlling the whole process with Python scripts I was about to make a workaround using OpenCV python library.

 

However, I will take a look at ImageMagick if the upper library is not fast enough.

Concerning the georeferencing, it could be a problem in case the erosion and/or dilation add pixel at the top or left borders, thus changing the world file. I am now not clear about how the dilating algorithm works in openCV and maybe one can specify to keep number of row and column.

Is the Orfeo Toolbox a ImageMagick plugin/derivate ?

In imageMagick the erode/dilation will not change the total number of pictures in the image, so if you extract the georeferencing information from the original image, you can restore it to the modified image.

 

 

Orefeo Toolbox is a completely unrelated software, it's an open source library for remote sensing imagery processing, and has a command line interface, so can also be integrated into fme.

 

https://www.orfeo-toolbox.org/

 

 

Userlevel 2
Badge +17

It's an interesting challenge. If the raster is a binary image, it may not be so difficult to define a workflow to perform eroding/dilating. The attachment is a prototype with 8-connectivity: raster-erode-dilate-prototype.zip

Left: Erode <-- Center: Original --> Right: Dilate

Badge

Sorry I can't completely open this workflow as I am running FME 2015...

In my case, I need to close (dilate --> erode) a Digital Terrain Model. So I need to complete holes in the terrain model.

But now that it is said, I think I might be able to close my terrain with: rastercellCoercer to points and then using a SurfaceModeller transformer.

Nevertheless, erode and dilate are operators that could be useful :)

Userlevel 4
Badge +25

I don't see an enhancement request in our database specifically for erosion and dilation functionality. But I do see this:

PR#24574: RasterExpressionEvaluator: lens processing - modify cell values based on surrounding values - kernel or focal functions

Would that help in this case? If so I can add your request there (it's already set to the top priority level, so I can't increase it any further!).

Failing that, I don't know how it could be done right now - unless you convert from raster to vector and use a Bufferer tool there - so I'll ask @dmitribagh to chime in.

Userlevel 2
Badge +17

Sorry I can't completely open this workflow as I am running FME 2015...

In my case, I need to close (dilate --> erode) a Digital Terrain Model. So I need to complete holes in the terrain model.

But now that it is said, I think I might be able to close my terrain with: rastercellCoercer to points and then using a SurfaceModeller transformer.

Nevertheless, erode and dilate are operators that could be useful :)

Edition for FME 2015.1.3.2: raster-erode-dilate-prototype-2015.zip
Userlevel 2
Badge +17

I don't see an enhancement request in our database specifically for erosion and dilation functionality. But I do see this:

PR#24574: RasterExpressionEvaluator: lens processing - modify cell values based on surrounding values - kernel or focal functions

Would that help in this case? If so I can add your request there (it's already set to the top priority level, so I can't increase it any further!).

Failing that, I don't know how it could be done right now - unless you convert from raster to vector and use a Bufferer tool there - so I'll ask @dmitribagh to chime in.

I have suggested this idea: Advanced Raster Cell Value Calculation. I think that any raster operations including erode/dilate could be performed through the expected transformer.

 

Userlevel 2
Badge +17
If your goal is to fill holes in a DTM with interpolated values, the RasterDEMGenerator might help you.

 

Userlevel 2
Badge +17

Sorry I can't completely open this workflow as I am running FME 2015...

In my case, I need to close (dilate --> erode) a Digital Terrain Model. So I need to complete holes in the terrain model.

But now that it is said, I think I might be able to close my terrain with: rastercellCoercer to points and then using a SurfaceModeller transformer.

Nevertheless, erode and dilate are operators that could be useful :)

If your goal is to fill holes in a DTM with interpolated values, the RasterDEMGenerator might help you.

 

Badge
If your goal is to fill holes in a DTM with interpolated values, the RasterDEMGenerator might help you.

 

I was able to perform the wanted closing after the RasterMosaicker:

 

--> PointCloudCombiner

 

--> PointCloudCoercer

 

--> SurfaceModeller (take TINsurface in output)

 

--> RasterDEMGenerator

 

--> Clip the raster using a buffered envelop

 

 

At first approach I thought raster closing was the solution, but the surfaceModeller performs fine for this case.

 

Thanks for all your response

 

Florian

 

 

As a work around: a binary raster dilate can be achieved by using (4) Affiners to create copies of the original image offset one pixel to the cardinal directions. The RasterMosaicker can be used to merge the resulting dilated image. Erode can be achieved by switching the data/no-data using a RasterExpressionEvaluator and then dilating the no-data region. Note be sure to set the image no-data value to the off-bit. if you are dealing with terrains an not binary images, you might try to stack the Affined copies into new bands of the original image and then use the RasterExpressionEvaluator to do raster math... min,max,average etc..

Badge +6

@florian67 I'm happy to report that we implemented support for raster lens processing in FME 2018.1 and 2019.0 with the new RasterConvolver transformer.

For more info see these articles:

https://blog.safe.com/2018/07/fme-and-convolution-evangelist176/

https://knowledge.safe.com/articles/74523/neighborhood-functions.html

https://knowledge.safe.com/articles/72616/edge-detection-with-the-rasterconvolver.html

https://knowledge.safe.com/articles/72505/raster-slope-calculations-as-a-rasterconvolver-exa.html

Reply