เมื่อเกิดมาแล้ว พบสิ่งประเสริฐ ไม่ศึกษาเพื่อเข้าถึง น่าเสียดายมาก
การปรับ 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.

ชื่อ :
Comment :
  *ใช้ code html ตกแต่งข้อความได้เฉพาะสมาชิก
 

โอม37
Location :
Florida United States

[Profile ทั้งหมด]

ฝากข้อความหลังไมค์
Rss Feed
Smember
ผู้ติดตามบล็อก : 1 คน [?]




มนุษย์คนหนึ่ง ชั่วดีมีปน หลง-วนตายเกิด พบรถด่วนขบวนสุดท้าย กำลังเข้าคิวตีตั๋ว
Group Blog
 
All Blogs
 
Friends' blogs
[Add โอม37's blog to your web]
Links
 

MY VIP Friend

 Pantip.com | PantipMarket.com | Pantown.com | © 2004 BlogGang.com allrights reserved.