0

I have used Qpixmap for embedding a normal image in Qlabel in user interface and its working totally fine but when I'm trying to embed a hyperspectral image its showing error

Following is the code used -

` library used - rasterio

img = rs.open('HYP.tif')
        profile = img.profile
        
        profile.update(count=3, compress='lzw')

        full_img = img.read()

        band1 = int(input('band number 1:'))
        band2 = int(input('band number 2:'))
        band3 = int(input('band number 3:'))

        b1 = img.read(band1)
        b2 = img.read(band2)
        b3 = img.read(band3)

        def normalize(array):
            #Normalizes numpy arrays into scale 0.0 - 1.0
            array_min, array_max = array.min(), array.max()
            return (array - array_min) / (array_max - array_min)

        # Normalize the bands
        redn = normalize(b3)
        greenn = normalize(b2)
        bluen = normalize(b1)

        rgb = np.dstack((bluen, redn, greenn))
        
        rgb1 = rgb.T
        rasterio.plot.show(rgb1)


        rgb3 = rgb1 / rgb1.max()
        rgb3 = rgb3 * 255
        rgb3 = rgb3.astype(numpy.uint32)
        rasterio.plot.show(rgb3)


        file_list = [rgb1.read, greenn, bluen]
        with rs.open('outimg.png', 'w', **profile) as dest:
            for band_nr, src in enumerate(file_list, start=1):
                dest.write(src, band_nr)


    self.label_2.setPixmap(QtGui.QPixmap('outimg.png'))

`

When I'm displaying the image using show() function its working fine and same for saving the image but when I'm trying to embed it in Qlabel (code -self.label_2.setPixmap(QtGui.QPixmap('outimg.png')))

its shwoing error -

foo: Sorry, can not handle images with 32-bit samples.

I want to know where is the mistake and how this can be done?

  • But what is the error?! Please show the full Python traceback and/or any Qt messages. – ekhumoro Nov 09 '22 at 12:44
  • Please click [edit] and correct your formatting. Please share a representative image - using Dropbox or Google Drive. Please be clearer about the error message and make sure your code is minimal and complete. – Mark Setchell Nov 10 '22 at 17:24

0 Answers0