P
P
Pavel2016-02-29 18:04:08
Qt
Pavel, 2016-02-29 18:04:08

How to convert an image to binary with a custom color table so that the quality of the result does not suffer?

Hello. There is this code:

QApplication a(argc, argv);

    //Адрес ресурса: :/<prefix>/<alias>
    const QString file_name = ":/ferrari.jpeg";
    QImage mono_img(file_name);

    QVector<QRgb> color_table(2);
    color_table[0] = QColor(Qt::white).rgb();
    color_table[1] = QColor(Qt::red).rgb();
    mono_img = mono_img.convertToFormat(QImage::Format_Mono, color_table);

    QLabel label;
    label.setPixmap(QPixmap::fromImage(mono_img));
    label.show();

    return a.exec();

Everything works, but the result of binarization is noticeably worse than when calling mono_img.convertToFormat(QImage::Format_Mono);Tell me how you can fix this.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question