I'm a student in CS doing an internship and I'm not familiar at all with GIS yet.
I have to display a GeoTIFF image (with a single band) into a QPixmap with PyQt4. So, I found some code that could help me in the GDAL library, but I think my conversion from my GeoTIFF file to a numpy array isn't correct. Here's why:
- When I display my QPixmap from a QImage (see code below), the only thing I have is a transparent band at the top and the rest of the image is just a huge black rectangle.
- When I type
gdalinfo <FILENAME>
in my console, it tells me that the maximum value is 165.146. However, when I get the max value from my numpy array, I get 544.843.
Here's the code:
import numpy as np
from osgeo import gdal
ds = gdal.Open("path/to/file.tiff")
mr_array = np.array(ds.ReadAsArray())
maxes = []
for sub in mr_array:
maxes.append(np.amax(sub))
print(max(maxes)) # => 544.843
mr_img = gray2qimage(mr_array) # comes from this script: https://github.com/sjara/brainmix/blob/master/brainmix/gui/numpy2qimage.py
self.pxm_mr = QtGui.QPixmap.fromImage(mr_img).scaled(371,301,QtCore.Qt.KeepAspectRatio)
self.lbl_pxmap_mr.setPixmap(self.pxm_mr)
The idea was to search where the problem was coming from: the GeoTIFF -> numpy array conversion, the numpy array -> QImage or the QImage -> QPixmap conversion. My guess is that it comes from the GeoTIFF -> numpy array because of the different maximums, but every code I find about that kind of conversion is basically the same as mine.
Am I right in thinking it comes from here?
If so, how could I correct this?
If not, where is my problem most likely to come from?