[Qt-interest] Enhanced monochrome conversion
M. Bashir Al-Noimi
mbnoimi at gmx.com
Thu Nov 26 08:36:08 CET 2009
Hi All,
It's easy to convert any image to monochrome format by using
QImage::convertToFormat like this:
pImage.convertToFormat(QImage::Format_Mono, Qt::MonoOnly|Qt::ThresholdDither|Qt::AvoidDither);
but convertToFormat always guessing that the value of conversion's
threshold is 255 where in some cases we need to use another threshold's
value. I checked out GIMP and I noticed that it uses an automatic method
for guessing threshold's value (see the example below) so I'm wondering:
*How I can convert images to monochrome format by using auto threshold's
value just like GIMP conversion method?*
Original
QImage conversion
Automatic GIMP conversion
*P.S*
I've wrote a stupid function for converting images to monochrome by
using a specified threshold's value as following but I need to know how
I can automatically specify threshold's value:
QImage getThresholdBW(QImage pImage, int threshold)
{
QImage result = pImage;
result.fill(255);
for(int x=0; x<pImage.width(); x++)
for(int y=0; y<pImage.height(); y++)
result.setPixel(x, y, qGray(pImage.pixel(x, y))>threshold?qRgb(255, 255, 255):qRgb(0, 0, 0));
return result;
}
-----
Best Regards
Muhammad Bashir Al-Noimi
My Blog: http://mbnoimi.net/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091126/510e03f7/attachment.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 01.jpg
Type: image/jpeg
Size: 28286 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091126/510e03f7/attachment.jpg
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 02.jpg
Type: image/jpeg
Size: 9160 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091126/510e03f7/attachment-0001.jpg
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 03.jpg
Type: image/jpeg
Size: 33083 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091126/510e03f7/attachment-0002.jpg
More information about the Qt-interest-old
mailing list