Change color masked pixels, land pixels
-
- Posts: 8
- Joined: Sun May 07, 2017 2:25 pm
Change color masked pixels, land pixels
Hello, I am processing S2 and L8 data with the newest version of ACOLITE and am looking for a solution to visualize all land area and masked pixels (clouds etc.) in black. The png output automatically is in light grey. IS there a possibility to change that in ACOLITE?
Re: Change color masked pixels, land pixels
Hi Anne
This is not currently supported in ACOLITE, but I will keep this in mind for a future update. You can always "remask" the ACOLITE output png files. I provide here an example Python 3 script which uses the pillow and numpy packages to do this.
Quinten
This is not currently supported in ACOLITE, but I will keep this in mind for a future update. You can always "remask" the ACOLITE output png files. I provide here an example Python 3 script which uses the pillow and numpy packages to do this.
Quinten
Code: Select all
## Remask ACOLITE output PNG files with different colour
## QV 2017-11-23 for ACOLITE forum
from PIL import Image
import numpy as np
## ACOLITE output to recolour
file = '/home/quinten/Software/ACOLITE/Output/LE07_L1TP_021040_20130202_20160909_01_T1_RHOW_561_LIN_0.00_0.10_map.png'
## set True if only one colour needs to be masked
## if False then all pixels with r==g==b will be masked (i.e. all whites, greys and blacks)
maskOneColour=True
## make new file name
file_out = file.split(".png")[0]+"_black_mask.png"
## source r,g,b value
rgb_mask = [230, 230, 230] ## light grey
## new mask color r,g,b value
rgb_target = [0,0,0] ## black
## read the image
img = Image.open(file)
## convert image to numpy array and set mutability
pixels = np.asarray(img)
pixels.setflags(write=1)
## extract colour arrays
r = pixels[:,:,0]
g = pixels[:,:,1]
b = pixels[:,:,2]
## get masked pixels
if maskOneColour:
sub = (r == rgb_mask[0]) * \
(g == rgb_mask[1]) * \
(b == rgb_mask[2])
else:
sub = (r-g == 0) * (r-b == 0) * (g-b ==0)
## apply new colour mask
r[sub] = rgb_target[0]
g[sub] = rgb_target[1]
b[sub] = rgb_target[2]
## construct new image array
new_img = np.dstack((r,g,b))
## save the image using PIL
img_out = Image.fromarray(new_img)
img_out.save(file_out)
Re: Change color masked pixels, land pixels
I provide here the input used for the script above and example output with maskOneColour set to False (all "white" r,g,b values were replaced by black). If you want to keep the latitude and longitude box in the output, you can first replace the black [0,0,0] by a practically white colour (e.g. [255,255,254]).
-
- Posts: 8
- Joined: Sun May 07, 2017 2:25 pm
Re: Change color masked pixels, land pixels
Thank you for the support