Colour browse generation from command line

Hi,
I want to create pseudo-colour (browse) images from S2 and S3 biophysical products (effectively single band greyscale). I can do this manually by creating and applying colour palettes (cpd files) through the Colour manipulation GUI tool.

How can I do this in bulk (from the command line)?
The pconvert - p option seems to use RGB profiles (which I don’t have) and GPT does not seem to offer options for applying palettes in the ‘Write’ operator.

Hi Thomas,

probably you overlooked the -c option of pconvert.

Doh!
Thanks Marco.
But now I seem to be using the option incorrectly.
My command line is:
/home/me/snap/bin/pconvert -c S2REP.cpd S2A_MSIL2A_BandMath_S2REP.dim

Which returns:
‘error: Color palette definition is only valid for image output’

You need to specify the the output format. e.g. ‘-f png’
Otherwise pconvert tries to convert the input to BEAM-DIMAP by default.

I originally used the -f png option but got:
Error: java.lang.reflect.InvocationTargetException
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at org.esa.snap.runtime.Launcher.lambda$run$0(Launcher.java:57)
at org.esa.snap.runtime.Engine.runClientCode(Engine.java:189)
at org.esa.snap.runtime.Launcher.run(Launcher.java:51)
at org.esa.snap.runtime.Launcher.main(Launcher.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.exe4j.runtime.LauncherEngine.launch(LauncherEngine.java:62)
at com.install4j.runtime.launcher.UnixLauncher.main(UnixLauncher.java:57)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.esa.snap.runtime.Launcher.lambda$run$0(Launcher.java:55)
… 9 more
Caused by: java.lang.NullPointerException
at org.esa.snap.pconvert.PConvertMain.(PConvertMain.java:366)
at org.esa.snap.pconvert.PConvertMain.main(PConvertMain.java:206)

Then I spotted the help instructions:
‘For image conversion:
png - Portable Network Graphics image format
jpg - JPEG image format
tif - GeoTIFF image format
bmp - Microsoft Bitmap image format
Note:
If image conversion is selected the product must at least
contain three bands to create an image.
If this is not the case, you must use one of the options -b or -p
to define the image content.’

My band maths product contains just 1 band so I thought ‘-f png’ option was invalid.

Right now you need to add also the option ‘-b 1’ for the first band.
I’ll improve this for the next version.

Got it. I understand the help page description now and have it working.

In the Colour manipulation tool, there is an option to render the CPD file as ‘Discrete colours’ rather than applying a colour blend / gradation across the data value range.

Is there an option in pconvert or in the CDP file to specify this rendering from the command line?

No this is unfortunately not possible.
But you can mimic this when you edit the text file and you duplicate each colour and each sample value.
I’ve added an example
7color_discrete.cpd (865 Bytes)

Hi guys,
I’d like to ask if there is way to apply 3 color palettes(R, G, B) to a RGB image simultaneously and generate a new RGB image(dim format) ?

I want to change the color bar of three of the bands of an image and do it in bulk, but I can’t find a way :cry: Is it possible through SNAP?

I think this is not possible.
If I understand you correctly you want to have 3 three different RGB images in one DIMAP. Is this correct?
Could you describe you use case in more detail? We might find a way to help you.

Sorry, I may not explain it clearly enough.
I have some original S2A images. For each image, I will use three of the bands to open the RGB window.

Now I have 3 color palettes(.cpd), I want to apply them to the three specific bands seperately for each original image.

Is there a way that I can handle it in bulk?

You can use pconvert with a colour palette for each of the bands and create an image.
For example like this
pconvert -B B3 -f png -c "D:\auxdata\color_palettes\5_colors.cpd" "H:\data\S2B_MSIL1C_20190506T081609_N0207_R121_T36SXA_20190506T104054_resampled.dim"

Writing this as dimap again is not possible with pconvert.

Thanks.
It seems that my task is not so easy to handle.

After applying color palettes for the specific bands, I hope to get a series of RGB images from them.
But it seems that pconvert could not simultaneously write the 3 bands into a dim format file.

:cold_sweat:Are there any other tools can help me with this?