简体   繁体   中英

Python Qt QImage is brightening or darkening the image depending on its contents

I'm using Pyside2, where I am displaying images on the screen as well as editing the images. I'm doing this by creating a QImage object by passing an OpenCV image. The following is the code I'm using:

# Convert hu into normalized values between 0 and 255
img = ( (img - img.max())/(img.max()-img.min()) ) * -1
img *= 255        
img = img.astype(int)
img = (255 - img)

# Convert to opencv format       
a = np.expand_dims(img, axis = 2)
img = np.concatenate((a, a, a), axis = 2)
img = np.require(img, np.uint8, 'C')

# QT Stuff
width, height, channel = img.shape     
bytesPerLine = 3 * width
imgQT = QImage(img, height, width, bytesPerLine, 
               QImage.Format_RGB888).rgbSwapped()
self.imgQP = QPixmap.fromImage(imgQT)
imgQPrs = self.imgQP.scaled(768, 768)
self.scene_edit.addPixmap(imgQPrs)
self.edit_l.setScene(self.scene_edit)

The problem is that the image brightness appears to auto adjust depending on what is getting displayed which is a big problem for this app, because it needs to be consistent. I can't really seem to figure out in the documentation how to set the brightness manually so it doesn't automatically adjust.

Ooops, OK stupid question. Normalizing causes the problem... of course. I will have to rethink how I convert from hounsfield units to pixel intensity.

Thanks to those who commented!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM