Пример #1
0
std::string dct16x16(const imagein::Image *img, imagein::Image_t<double> **resImg, imagein::Image **invImg, bool truncMode, int truncLimit, int nBitInit, double slope)
{
    string returnval;
/*----------------------------------------------------------------------
*
*     OUVERTURE ET LECTURE DU FICHIER IMAGE ORIGINE
*
*----------------------------------------------------------------------*/
    Image_t<double>* tmpImg;
    if(img->getWidth() % 16 != 0 || img->getHeight() % 16!= 0){
        int addcol = 0;
        int addlign = 0;
        if(img->getWidth()  % 16 != 0 )
            addcol = 16 - ( img->getWidth() % 16 );
        if(img->getHeight()  % 16 != 0 )
            addlign = 16 - ( img->getHeight() % 16 );
        
        tmpImg = new Image_t<double>(img->getWidth() + addcol, img->getHeight() + addlign, img->getNbChannels());
        for(unsigned int c = 0; c < tmpImg->getNbChannels(); c++) {
            for(unsigned int i = 0; i < tmpImg->getWidth() ; i++) {
                for(unsigned int j = 0; j < tmpImg->getHeight() ; j++) {
                    
                    tmpImg->setPixel(i, j, c, (double) img->getPixel(min(i, img->getWidth()-1 ), min(j, img->getHeight()-1), c));
                
                }
            }
        }
    }
    else {
       tmpImg = Converter<Image_t<double> >::convert(*img);
    }
/*----------------------------------------------------------------------
*
*     CALCUL DES COEFFICIENTS DE LA MATRICE DE TRANSFORMATION
*
*----------------------------------------------------------------------*/
    double coef[16];
    cosi(coef);
/*----------------------------------------------------------------------
*
*     TRANSFORMATION
*
*----------------------------------------------------------------------*/
    dct(tmpImg, coef);
/*----------------------------------------------------------------------
*
*     CODAGE
*
*----------------------------------------------------------------------*/
    if(truncMode) {
        returnval = tronc(tmpImg, truncLimit);
    }
    else {
        returnval = reduce(tmpImg, nBitInit, slope);
    }

/*----------------------------------------------------------------------
*
*     STOCKAGE DE L'IMAGE TRANSFORMEE DANS UN FICHIER
*
*----------------------------------------------------------------------*/
    *resImg = new Image_t<double>(*tmpImg);

/*----------------------------------------------------------------------
*
*     TRANSFORMATION INVERSE
*
*----------------------------------------------------------------------*/
    idct(tmpImg, coef);

/*----------------------------------------------------------------------
*
*     STOCKAGE DE L'IMAGE RESULTAT DANS UN FICHIER
*
*----------------------------------------------------------------------*/
    *invImg = Converter<Image>::convertAndRound(*tmpImg);
    delete tmpImg;
    return returnval;
}
Пример #2
0
void RandomImgOp::operator()(const imagein::Image*, const std::map<const imagein::Image*, std::string>&) {
    QDialog* dialog = new QDialog(qApp->activeWindow());
    dialog->setWindowTitle(qApp->translate("RandomImgOp", "Parameters"));
    dialog->setMinimumWidth(180);
    QFormLayout* layout = new QFormLayout(dialog);

    QGroupBox* radioGroup = new QGroupBox(qApp->translate("RandomImgOp", "Image type"), dialog);
    QRadioButton* intButton = new QRadioButton(qApp->translate("RandomImgOp", "8-bit integer"));
    QRadioButton* floatButton = new QRadioButton(qApp->translate("RandomImgOp", "Floating point"));
    QHBoxLayout* radioLayout = new QHBoxLayout(radioGroup);
    radioLayout->addWidget(intButton);
    radioLayout->addWidget(floatButton);
    intButton->setChecked(true);
    layout->insertRow(0, radioGroup);

    QSpinBox* widthBox = new QSpinBox(dialog);
    widthBox->setRange(0, 65536);
    widthBox->setValue(512);
    layout->insertRow(1, qApp->translate("RandomImgOp", "Width : "), widthBox);

    QSpinBox* heightBox = new QSpinBox(dialog);
    heightBox->setRange(0, 65536);
    heightBox->setValue(512);
    layout->insertRow(2, qApp->translate("RandomImgOp", "Height : "), heightBox);

    QSpinBox* channelBox = new QSpinBox(dialog);
    channelBox->setRange(1, 4);
    channelBox->setValue(3);
    layout->insertRow(3, qApp->translate("RandomImgOp", "Number of channels : "), channelBox);

    QWidget* intRangeWidget = new QWidget(dialog);
    QHBoxLayout* intRangeLayout = new QHBoxLayout(intRangeWidget);
    QSpinBox* intMinBox = new QSpinBox(dialog);
    QSpinBox* intMaxBox = new QSpinBox(dialog);
    intMinBox->setRange(0, 255);
    intMaxBox->setRange(0, 255);
    intMinBox->setValue(0);
    intMaxBox->setValue(255);
    intRangeLayout->addWidget(new QLabel(qApp->translate("RandomImgOp", "Range : ")));
    intRangeLayout->addWidget(intMinBox);
    intRangeLayout->addWidget(new QLabel(qApp->translate("RandomImgOp", " to ")));
    intRangeLayout->addWidget(intMaxBox);
    layout->insertRow(4, intRangeWidget);

    QWidget* floatRangeWidget = new QWidget(dialog);
    QHBoxLayout* floatRangeLayout = new QHBoxLayout(floatRangeWidget);
    QDoubleSpinBox* floatMinBox = new QDoubleSpinBox(dialog);
    QDoubleSpinBox* floatMaxBox = new QDoubleSpinBox(dialog);
    floatMinBox->setValue(0.0);
    floatMaxBox->setValue(1.0);
    floatMinBox->setRange(-65536, 65536);
    floatMaxBox->setRange(-65536, 65536);
    floatRangeLayout->addWidget(new QLabel(qApp->translate("RandomImgOp", "Range : ")));
    floatRangeLayout->addWidget(floatMinBox);
    floatRangeLayout->addWidget(new QLabel(qApp->translate("RandomImgOp", " to ")));
    floatRangeLayout->addWidget(floatMaxBox);
    layout->insertRow(5, floatRangeWidget);
    floatRangeWidget->hide();

    layout->setSizeConstraint(QLayout::SetFixedSize);

    QObject::connect(intButton, SIGNAL(toggled(bool)), intRangeWidget, SLOT(setVisible(bool)));
    QObject::connect(floatButton, SIGNAL(toggled(bool)), floatRangeWidget, SLOT(setVisible(bool)));

    QPushButton *okButton = new QPushButton(qApp->translate("Operations", "Validate"), dialog);
    okButton->setDefault(true);
    layout->addWidget(okButton);
    QObject::connect(okButton, SIGNAL(clicked()), dialog, SLOT(accept()));

    QDialog::DialogCode code = static_cast<QDialog::DialogCode>(dialog->exec());

    if(code!=QDialog::Accepted) {
        return;
    }

    if(intButton->isChecked()) {

        Image* resImg = new Image(widthBox->value(), heightBox->value(), channelBox->value());
        RandomLib::Random random;
        for(unsigned int c = 0; c < resImg->getNbChannels(); ++c) {
            for(unsigned int j = 0; j < resImg->getHeight(); ++j) {
                for(unsigned int i = 0; i < resImg->getWidth(); ++i) {
                    Image::depth_t value = random.IntegerC<Image::depth_t>(intMinBox->value(), intMaxBox->value());
//                    Image::depth_t value = 256. * (rand() / (RAND_MAX + 1.));;
                    resImg->setPixel(i, j, c, value);
                }
            }
        }
        this->outImage(resImg, qApp->translate("Operations", "Random image").toStdString());

    }
    else if(floatButton->isChecked()) {

        Image_t<double>* resImg = new Image_t<double>(widthBox->value(), heightBox->value(), channelBox->value());
        RandomLib::Random random;
        for(unsigned int c = 0; c < resImg->getNbChannels(); ++c) {
            for(unsigned int j = 0; j < resImg->getHeight(); ++j) {
                for(unsigned int i = 0; i < resImg->getWidth(); ++i) {
                    double min = floatMinBox->value();
                    double max = floatMaxBox->value();
//                    double width = max - min;
//                    double value = min + (double)rand() * width / RAND_MAX;
                    double value = random.FixedN<double>();
                    value = value*(max-min) + min;
                    resImg->setPixel(i, j, c, value);
                }
            }
        }
        this->outDoubleImage(resImg, qApp->translate("Operations", "Random image").toStdString(), true);

    }
}