2

I want to process a 16 bit satellite image(.geotiff) file in python using GDAL and other imaging libraries like PIL. But when I display image, it is not displayed properly as it is 16 bit. Is there any way to display it properly in python? Please help. Code is given below.

Algorithm is as below:

  1. Open geotiff raster using GDAL library.
  2. Get it in the form of array and process as per requirement.
  3. Write processed image into output raster.

This code works and output raster (image) can be seen in other remote sensing software like Arcmap, QGIS, ENVI. But during processing, I need to see resultant image in python. Due to 16 bit nature of image, it shows only black and white (no other grey shade) color in image.

Is there any way that I can see output image in python only instead of going to remote sensing software?

Code is given below. (write raster part is removed from code)


from PIL import Image,ImageOps
import numpy as np
import scipy as sp
import pywt
from osgeo import gdal
from osgeo import gdal_array
from osgeo import osr
import cv2
#from osgeo.gdalconst import *
#import matplotlib.pylab as plt

gdal.AllRegister()

################## Read Raster #################
inRaster='C:\python\Results\Database\Temporary data base\clipped_26July2017\HV_clip9Nov.tif'

inDS=gdal.Open(inRaster,1)
geoTransform = inDS.GetGeoTransform()
band=inDS.GetRasterBand(1)
datatype=band.DataType
proj = inDS.GetProjection()
rows = inDS.RasterYSize
cols=inDS.RasterXSize
data=band.ReadAsArray(0,0,cols,rows)#extraction of data to be processed#
im=Image.fromarray(data)#-----creation of image from raster data----#

ca1,(ch1,cv1,cd1)=pywt.dwt2(im,'db1');
ca2,(ch2,cv2,cd2)=pywt.dwt2(ca1,'db1')
ca3,(ch3,cv3,cd3)=pywt.dwt2(ca2,'db1')
coeff3=ca3,(ch3,cv3,cd3)
c_op3=pywt.idwt2(coeff3,'db1');
c_op3=Image.fromarray(c_op3)
c_op3.show()
coeff2=ca2,(ch2,cv2,cd2)
c_op2=pywt.idwt2(coeff2,'db1');
c_op2=Image.fromarray(c_op2)
c_op2.show()
coeff1=ca1,(ch1,cv1,cd1)
c_op1=pywt.idwt2(coeff1,'db1');
[u,v]=np.shape(c_op1)
c_op1=np.delete(c_op1,u-1,0)#deletion of last row, appended by pywt due to odd size of image
c_op1=np.delete(c_op1,v-1,1)#deletion of last column, appended by pywt due to odd size of image

closed as off-topic by ahmadhanb, Kersten, whyzar, xunilk, tinlyx Dec 23 '17 at 1:00

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions seeking help to debug/write/improve code must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Providing a clear problem statement and evidence of a code attempt will help others to help you. See: How to create a Minimal, Complete, and Verifiable example." – ahmadhanb, Kersten, whyzar, xunilk, tinlyx
If this question can be reworded to fit the rules in the help center, please edit the question.

  • can you show us your python code so we can determine where the error might be? – LaughU Dec 22 '17 at 8:01
  • do you want to perform contrast stretching? you could, for example, calculate percentile using numpy.percentile and then rescale intensities to 0-255 using skimage.exposure.rescale_intensity – dr_times Dec 22 '17 at 15:02