APOLLO & ECW/JP2 Discussions

Wondering how others have configured their ERDAS APOLLO server or what data they are crawling? The ERDAS APOLLO Discussion board is a place to find information, share ideas and more. Join the community, connect, contribute and share.
Showing results for 
Search instead for 
Do you mean 
Reply
Highlighted
Staff
Posts: 137
Registered: ‎05-31-2016

Formula for adding transparency to old ecw files (knock out White or Black)

[ Edited ]

Here is a way to configure an Apollo Essentials style with a formula to knock out the White or Black areas in an ECW.

 

Before

Before

 

After

after

 

 

In some imagery (depending on the colours in the image) it may make lots of little holes, but I have found it is a quick way to add transparency to old imagery when you don't have time to recompress the image with the transparent areas defined properly.

 

 

The following method will work for 8 bit 3 band images.

 

Configure the style and enter the following formula

Select the Red Layer

 

if (( INPUT1 > 245) and
    ( INPUT2 > 245) and
    ( INPUT3 > 245))
then null else INPUT1

 

press Validate

 

Set the following inputs

INPUT1 = Red

INPUT2 = Green

INPUT3 = Blue

 

 

 

Use the same formula for the Green and Blue layers with a slightly different configuration for the Inputs

 

Select the Green Layer

Enter the formula

Press Validate

 

Set the following inputs

INPUT1 = Green

INPUT2 = Red

INPUT3 = Blue

 

Select the Blue Layer

Enter the Formula

press Validate

 

Set the following inputs

INPUT1 = Blue

INPUT2 = Red

INPUT3 = Green

 

Press OK

Press OK

 

You should now see transparency applied to the white areas in the image.

Pan and zoom around the image to make sure there are not too many holes and adjust the cut off value (245 in the formula above)

 

 

 

If you want to make the black areas transparent use the following formula for all 3 bands 

if (( INPUT1 < 10) and
    ( INPUT2 < 10) and
    ( INPUT3 < 10))
then null else INPUT1

 You may need to adjust the cut off value (10 in the formula above) to get the best results for your imagery .

 

 

I have done some testing of this method for adding transparency to images with white edges with good results. For performance and image quality reasons the best way is to add the transparency to the image and recompress, but this may be a good workaround for an image that is not used all the time.

 

If this works for you let me know.

 

 

Regards,

Phil

Highlighted
Moderator
Moderator
Posts: 377
Registered: ‎11-16-2015

Re: Formula for adding transparency to old ecw files (knock out White or Black)

 Thanks for the nice tip! Smiley Happy

 

The point is this is even better than using the transparent option in the Post process in any case because this is applied before the contrast enhancement ("output transform"). So, the areas that are recoded to black or white (typically lakes or clouds) with the stretch are not masked.

 

To make your formula easier to understand, I would suggest just to change the last line depending of the band:

red:

 

then null else INPUT1

green:

 

then null else INPUT2

blue:

then null else INPUT3

 

So you can keep the same bands for all the inputs for all layers.

INPUT1 = Red

INPUT2 = Green

INPUT3 = Blue

Highlighted
Staff
Posts: 137
Registered: ‎05-31-2016

Re: Formula for adding transparency to old ecw files (knock out White or Black)

[ Edited ]

Also the transparent option only allows for the selection of 1 colour and does not work with ecw or jp2 files because the lossy compression causes white or black pixels to be visibly white or black and not solid white(255,255,255) or black(0,0,0).

 

 

 

I thought about doing it that way but unfortunately there is a problem declaring variables (that I have logged).

Doing it this way, when you change the cut-off point all you need to do is change one formula then copy paste it to the other bands.

 

When the bug is fixed I will update the post.