Skip to main content

Hi.

I'm clearly a novice wrt. handling rasters in FME. I simply have trouble with understanding the fundamentals.

E.g., I want to replace all white (1,1,1) cell values with a transparent cell (x,x,x,1).

I looked at the RasterCellValueReplacer, but it doesn't handle colors the FME way, so it's a dead end.

And the other raster transformers I've looked at all seemed off-mark to me.

How do I accomplish this simple task ?

Do I need to explode the raster into individual cells (and later reassemble) to do it ?

Cheers.

Not a RasterGuru either but RasterCellValueReplacer sounds like what you want.

If I understand correctly you want a NoDataValue for the cells to create the transparency effect. A NoData value is a value which not interferes with the valid data range. Something like -9999.

But someone with more Raster-Fu will correct me anyway :)


Take a look at the RasterBandNodataSetter


Not a RasterGuru either but RasterCellValueReplacer sounds like what you want.

If I understand correctly you want a NoDataValue for the cells to create the transparency effect. A NoData value is a value which not interferes with the valid data range. Something like -9999.

But someone with more Raster-Fu will correct me anyway :)

Alas, this is from the help:

  • RGB and RGBA color models are not supported by this transformer.
  • Rasters that contain bands with palettes are not supported by this transformer.

Take a look at the RasterBandNodataSetter

Yes, I've already looked at it, and found it to be of limited use as-is. I cannot select the all white pixels with it.


Yes, I've already looked at it, and found it to be of limited use as-is. I cannot select the all white pixels with it.

How many bands does your input have?


How many bands does your input have?

It's a PNG, and according to Inspector, it has 4 bands. So the alpha band seems to be present, so I (just) need to select all (1,1,1) pixels, and assign an alpha value of 1, or ?


Ah, the RasterExpressionEvaluator does the trick.

Defined 4 bands, the first three set to Preserve, and the last (alpha, A[3]) set to the UInt8 expression:

if (A[0]==255 && A[1]==255 && A[2]==255, 255, A[3])


It's a PNG, and according to Inspector, it has 4 bands. So the alpha band seems to be present, so I (just) need to select all (1,1,1) pixels, and assign an alpha value of 1, or ?

I would normally do this by removing the alpha band, selecting all remaining bands, use the rasterbandnodatasetter with a nodatavalue of 255, then a rasterinterpretationcoercer to turn to RGBA with 'Create alpha band from nodata'

 

There are probably better ways however


Ah, the RasterExpressionEvaluator does the trick.

Defined 4 bands, the first three set to Preserve, and the last (alpha, A[3]) set to the UInt8 expression:

if (A[0]==255 && A[1]==255 && A[2]==255, 255, A[3])

Is fully transparent not zero?


Ah, the RasterExpressionEvaluator does the trick.

Defined 4 bands, the first three set to Preserve, and the last (alpha, A[3]) set to the UInt8 expression:

if (A[0]==255 && A[1]==255 && A[2]==255, 255, A[3])

Correction: the fourth band needs to be Alpha8.

I suppose that the other three bands could be Red8, Green8, and Blue8 too.


Correction: the fourth band needs to be Alpha8.

I suppose that the other three bands could be Red8, Green8, and Blue8 too.

Could you share a sample workspace? Trying to learn something.


@lifalin2016

(check the properties of the raster. FeatureInformationWindow or RasterPropertyExtractor)

 

If your raster already has a alpha band. (else add one using RasterBandAdder)

Use a RasterBandNodataSetter to set the no data to 255.

Then use a RasterInterpretationCoercer to RGBA32 (I assume)

RGB to RGBA : create alpha band from no data.

 

 

 

 

 


Could you share a sample workspace? Trying to learn something.

remove_white_background.fmwt


With RasterCellValueReplacer you have to hope that you are not making valid white cells transparent.

With no data setter you can set it without replacing cell values.

 


@lifalin2016

 


Alas, this is from the help:

  • RGB and RGBA color models are not supported by this transformer.
  • Rasters that contain bands with palettes are not supported by this transformer.

I've just (this very week) been helping out with updates to the raster documentation, and this is one part of the help I flagged as being incorrect. The RasterCellValueReplacer certainly can work on RGB and RGBA rasters. The trick is to use the RasterSelector beforehand, otherwise it will carry out the same action on every band.

Having said that, I don't know that it helps here. It only sets values for the band that it filters by; so you can't fill the replace values parameter with band A[0] then set A[3] in the New Value field.


Is fully transparent not zero?

Correct. It should be if (A[0]==255 && A[1]==255 && A[2]==255, 0, A[3])


So what is the exact transformer/expression used to make white border around the raster transparrent?

 

I am a raster novice too, I have a task to process a ecw which has 4 bands inlcude alpha8 band, the aim is to get rid of the white border around the interested area and display it as transparent, but the white borders are not in rectanlguar shape.

 

Have done lots of Google research this week and have came across this article and found it is mostly helpful but can't open the workspace attached here, tried everything mentioned here in the posts, still not achieving desired results.😟


So what is the exact transformer/expression used to make white border around the raster transparrent?

 

I am a raster novice too, I have a task to process a ecw which has 4 bands inlcude alpha8 band, the aim is to get rid of the white border around the interested area and display it as transparent, but the white borders are not in rectanlguar shape.

 

Have done lots of Google research this week and have came across this article and found it is mostly helpful but can't open the workspace attached here, tried everything mentioned here in the posts, still not achieving desired results.😟

​ 

 

Either you replace the value using a expressionevaluator as David2 shows (risking removing white pixels in your image as wel) or you simply use an polygon to clip the border. Use the resulting nodata as your transparency.

 

Safe should make the Gdal caller they promised years ago.

Or you can instal PIL for python.

Both let you do lots of rastermanipulation.


Reply