1

I am using Rasterio to open a panchromatic GeoTiff image file. The syntax I used to open the GeoTIFF file using Rasterio:

import rasterio

src = rasterio.open('Birmingham_Shuttleworth_s106_20200409T191236Z_Basic_Panchromatic/20200409_191236_ssc6d3_0015_basic_panchromatic.tif')
band_1 = src.read(1)

The array I can see after doing

In [23]: band_1
Out[23]: 
array([[3466, 3865, 3929, ..., 4472, 4520, 4456],
       [3546, 3657, 3721, ..., 4568, 4728, 4504],
       [3562, 3689, 3945, ..., 4696, 4504, 4568],
       ...,
       [5606, 5622, 5478, ..., 4376, 4264, 4424],
       [5558, 5526, 5462, ..., 4600, 4504, 4536],
       [5558, 5510, 5462, ..., 4824, 4696, 5175]], dtype=uint16)

However, when I open the same GeoTIFF file using OpenCV:

import numpy as np
import cv2 as cv
from matplotlib import pyplot as plt

img = cv.imread('Birmingham_Shuttleworth_s106_20200409T191236Z_Basic_Panchromatic/20200409_191236_ssc6d3_0015_basic_panchromatic.tif',0)

I can see:

In [44]: img
Out[44]: 
array([[13, 15, 15, ..., 17, 17, 17],
       [13, 14, 14, ...,  0,  0,  0],
       [13, 14, 15, ...,  0,  0,  0],
       ...,
       [21, 21, 21, ..., 13,  9, 11],
       [21, 21, 21, ...,  0,  0,  0],
       [21, 21, 21, ...,  0,  0,  0]], dtype=uint8)

I see that the pixel type(?) is uint8 in OpenCV and uint16 in Rasterio. Below are some of the questions that I have.

  1. What and why is this happening?
  2. What are those numbers that I see in the arrays? Are they pixel values? If yes, why are they not from 0-255? Do panchromatic image pixels have a different range?

I have just started image processing using Python.

1
  • 1
    Welcome to GIS SE. Please edit your question to include a single, focused question rather than 5 related questions. – Aaron Jan 4 at 18:46
4

I could reproduce these results with Landsat-8 panchromatic band.

When you are using cv2.imread(fl,0) it reads image as greyscale 8 bit (0-255), you should either read it as cv2.imread(fl,cv2.IMREAD_UNCHANGED) or cv2.imread(fl,-1) since your original image has 16 bit depth (0-65535)

as for the other question

What are those numbers that I see in the arrays? Are they pixel values? If yes, why are they not from 0-255? Do panchromatic image pixels have a different range?

The numbers are resulted from OpenCV simple depth scaling and is estimated as following: (pixel_value/65535)*255 with 65535 being the maximum possible value of 16 bit image and 255 maximum possible value of 8 bit image.

For example in your rasterio output pixel value at (0,0) is 3466, (3466/65535)*255=13.480827308501876 which is the same (with an exception of rounding) as your OpenCV output at (0,0)

Not the answer you're looking for? Browse other questions tagged or ask your own question.