Question

Clipping and blending rasters...An easy method?

  • 28 February 2014
  • 8 replies
  • 26 views

is there an easy way to clip a raster based on a shape file with a feathered edge?

 

So use the "clipper" but not just end up with a harsh cut, as I want to merge this with another raster dataset and for them to blend in. or is the "Alpha Compositing: Blending Two Raster Images" method the only realistic method?

 

 

The effect i'm looking for is similar to that of a feathered lasso in Photoshop.

8 replies

Badge +4
Hi Ash, I'm no expert in dealing with rasters, however the way to 'feather' them would be to ensure that you're clipping shapefiles overlap and them use the alpha comositing as you say.

 

 

in effect resample the overlapping part of your images to 'feather' them?
Badge +3
Yes, for blending with a alpha gradient u must create a composition map with buffered amount and radialy (if that is what u want) calculate the aplha strength.

 

Then raster combine the alpha map with your raster.

 

 

Wich is basicaly what photo software do btw.
Thanks for the responses guys. I shall give these a go
Badge

Just wondering if anything has changed on this front in the last 5 years?

 

I have seen the MapnikRasterizer but blending seems awkward to set up, particularly if you have more than one layer to blend.

Badge +2

Just wondering if anything has changed on this front in the last 5 years?

 

I have seen the MapnikRasterizer but blending seems awkward to set up, particularly if you have more than one layer to blend.

Hi @btl, Thanks for your question. There are a couple of methods that might be worth trying:

 

Here is an article explaining in more detail on how to blend two rasters: https://knowledge.safe.com/articles/1219/alpha-compositing-blending-two-raster-images.html

There is also a custom transformer in the hub, which might work better for your scenario involving multiple layers: https://hub.safe.com/transformers/rasterblendmosaicker#description

Full disclosure, I've not tried this workflow, but hopefully these resources might be helpful to you.

Badge +1

Just wondering if anything has changed on this front in the last 5 years?

 

I have seen the MapnikRasterizer but blending seems awkward to set up, particularly if you have more than one layer to blend.

The MapnikRasterizer has compositing operations and uses anti-aliasing which will give you a feathered edge to a feature. Not too difficult to set up once you understand the order of layers.

Its also worth looking at the RasterConvolver which adds a whole other set of image tools, such as Gaussian Blur

 

Badge +3

@btl

Option would be to use (for instance) PIL. (which appears to be in the standard install)

 

Here is a simple blurr script. Blurs in 8 stages

(because of issues with the show method (which is commented out in this example), i used the webbrowser apporach to view it)

 

import fme

 

import fmeobjects

 

import webbrowser

 

from PIL import Image, ImageFilter # imports the library

 

def huh(feature):

 

 

 

original = Image.open("H:\\Documents\\My Pictures\\Manneke.jpg") # load an image from the hard drive

 

for x in range(8):

 

 

blurred = original.filter(ImageFilter.BLUR) # blur the image

 

fnb = "H:\\Documents\\My Pictures\\Manneke_b_"+str(x)+".jpg"

 

blurred.save(fnb)

 

 

#original.show() # display both images

 

#blurred.show()

 

 

webbrowser.open(fnb)

 

#original = Image.open(fnb)
Badge +3

@btl

 

Here is a belning example using PIL (replace wiht our own pics)

 

import fme

 

import fmeobjects

 

import webbrowser

 

from PIL import Image, ImageFilter # imports the library

 

 

def huh(feature):

 

 

im1= Image.open("H:\\Documents\\My Pictures\\Manneke.jpg")

 

im2= Image.open("H:\\Documents\\My Pictures\\Manneke_b_7.jpg")

 

im3= Image.open("H:\\Documents\\My Pictures\\pdfpf.png")

 

target_mode = im1.mode

 

target_size = im1.size

 

zero=tuple((0, 0))

 

crop_t= zero + target_size

 

 

print("Targetmode is "+im1.mode+ " with size "+ str(target_size) +" and sourcemode is "+im3.mode+"with size "+ str(im3.size))

 

 

im3c=im3.crop(crop_t)

 

im_out = Image.blend(im1, im3c, 0.5)

 

#im_out = Image.alpha_composite(im1, im2)

 

i_name = "H:\\Documents\\My Pictures\\A_comp.jpg"

 

im_out.save(i_name)

 

 

#webbrowser.open(i_name)

 

 

 

Reply