Oft-addpct.py

From Open Foris Wiki

Jump to: navigation, search

oft-addpct.py - adds pseudo color table to an image


Usage: oft-addpct.py <inputfile> <outputfile>

Description: Adding a pseudo color table to an image keeps the original values of the image, but ensures that classes are shown in pre-defined colors, no matter which application is used to open the image.


After defining the first line, the command will ask for the text file containing the color table:
Give LUT file name: <colortable>

Where:

  • <inputfile> is an image file
  • <outputfile> is an image file (if it is the same as <inputfile>, <inputfile> will be overwritten>)
  • <colortable> is a text file with 4 or 5 columns containing the color table in the following format:
    • 1st column: class value
    • 2nd - 4th column: RGB values
    • optional: 5th column for alpha, if not set, it is assumed to be 255
    • Important: The <colortable> must NOT contain any empty lines!
    • see Wikipedia for more information on RGBA color space.

The <colortable> could look like this:

1 103 51 1 255
2 254 0 0 255
3 0 0 254 255
4 0 255 0 255

Example:

cd /home/.../OFGT-data
  • Create the colortable for the file images/forestc.tif. If you do not know which classes are present in images/forestc.tif, you could use oft-stat with images/forestc.tif both as input and mask file. The first column of the mask file shows all present classes (besides 0).

Create a text file called txt/coltable.txt, with the first column indicating all possible classes. It could look like this:

1 0 0 0 0
44 122 122 0 255
33 103 51 1 255
55 4 253 255 255
22 122 0 122 255
11 255 0 0 255
4 122 122 122 255
3 255 255 0 255
2 200 200 200 255
6 0 255 0 255

Important: Make sure that the text file does not contain any empty lines.

  • Run oft-addpct.py:
oft-addpct.py images/forestc.tif results/forestcolor.tif
  • The command will ask you about the colortable file:
Give LUT file name: 

Enter the path to your color table file and hit enter:

txt/coltable.txt
  • You can visualize the result in QGIS:
qgis results/forestcolor.tif



Back to Open Foris Toolkit Main Page

Back to Tools & Exercises



Personal tools