การปรับ Gamma และ Contrast ของ QPixmap ใน PyQt4
ดังแปลงมาจาก C++ ที่นี่ //www.qtforum.org/article/26907/contrast-transparency-brightness.html
ตามนี้ครับ
def changeContrast(self, value, contrast): rt = int(( value - 127 ) * contrast / 100 ) + 127 return rt if rt in range(256) else 0 if rt < 0 else 255 def changeGamma(self, value, gamma ): rt = int(pow(value/255.0, 100.0/gamma)*255) return rt if rt in range(256) else 0 if rt < 0 else 255 @pyqtSlot() def on_butGramma_clicked(self): progress = QProgressDialog("Take a picture ...", "Abort", 0, 2) progress.show() progress.setValue(1) pMap = self.pil2qpixmap(self.cam.getImage(timestamp=3, boldfont=1)) im = pMap.toImage() if im.numColors() == 0: if im.format() != QImage.Format_RGB32: im = im.convertToFormat(QImage.Format_RGB32) table = [] for i in range(256): table.append(self.changeGamma(i, 150)) table[i] = self.changeContrast(table[i], 200) if im.hasAlphaChannel(): pass else: for y in range(im.height()): for x in range(im.width()): pix = im.pixel(x, y) value = qRgb(table[qRed(pix)], table[qGreen(pix)], table[qBlue(pix)]) im.setPixel(x, y, value) self.label.setPixmap(pMap.fromImage(im))
Create Date : 05 กรกฎาคม 2554 |
Last Update : 5 กรกฎาคม 2554 23:41:39 น. |
|
0 comments
|
Counter : 396 Pageviews. |
|
|