Could you share the pnm2ptif?

26 views
Skip to first unread message

Xiao Xiao

unread,
Nov 17, 2022, 11:43:15 PM11/17/22
to Lunaserv
Dear Nick,

It is mentioned in the documentation that the pnm2ptif can generate mask files. But I cannot find the pnm2ptif anywhere.

I'm trying to generate 1-bit mask files by gdal_translate. But the mask file by gdal_translate is an 8-bit.

Could you share the pnm2ptif?

Thanks much
Xiao

Xiao Xiao

unread,
Nov 23, 2022, 9:13:41 AM11/23/22
to Lunaserv
Hi Nick,

I'm trying to create 1-bit mask files by gdal_translate. The command is as follows:
gdal_translate  -b 1 -co nbits=1 -of gtiff -co 'COMPRESS=DEFLATE' -co 'TILED=YES' -co 'BLOCKXSIZE=256' -co 'BLOCKYSIZE=256' in.tif bit.ptiff

The last few lines of gdalinfo of this bit.ptiff are as follows:
Band 1 Block=256x256 Type=Byte, ColorInterp=Palette
  Image Structure Metadata:
    NBITS=1
  Color Table (RGB with 2 entries)
    0: 0,0,0,255
    1: 255,255,255,255


Then I use rasterio to create the 1-bit mask file while the out.ptiff is opened with 1 byte (refer to Tamar, https://groups.google.com/g/lunaserv/c/K8Xgo0kGNHE). The core codes are as follows:
new_dataset = rasterio.open('out.ptiff', 'w',
                            driver='GTiff',
                            compress="DEFLATE",
                            tiled=True, blockxsize=256, blockysize=256,
                            height=data.height, width=data.width,
                            count=1, dtype='uint8', nbits=1,
                            crs=data.crs, transform=data.transform)

The gdalinfo of out.ptiff  by rasterio is similar as the gdalinfo of bit.ptiff by gdal_translate. 
I'd like to know if these ptiffs created by these methods are correct 1-bit mask files.
These ptiffs are in the attached zipfile.

Look forward to your reply.
Thank you.
Xiao
1-bit_mask_file.zip

Xiao Xiao

unread,
Dec 4, 2022, 8:49:45 AM12/4/22
to Lunaserv
There is something wrong with the 1-bit mask file created by gdal_translate from RGB tiff. Some of the valid data have been processed to zero. As shown in the figure below
mask_band.png
I have created the correct 1-bit mask files by rasterio.  
Reply all
Reply to author
Forward
0 new messages