void Color::CubicInterp(const Color& dest,float s) { a = CubicInterpolation(a,dest.a,s); r = CubicInterpolation(r,dest.r,s); g = CubicInterpolation(g,dest.g,s); b = CubicInterpolation(b,dest.b,s); }
void calculate() { splines_.resize(this->zData_.rows()); for (Size i=0; i<(this->zData_.rows()); ++i) splines_[i] = CubicInterpolation( this->xBegin_, this->xEnd_, this->zData_.row_begin(i), CubicInterpolation::Spline, false, CubicInterpolation::SecondDerivative, 0.0, CubicInterpolation::SecondDerivative, 0.0); }
Real derivativeY(Real x, Real y) const { std::vector<Real> section(splines_.size()); for (Size i=0; i<splines_.size(); i++) section[i]=splines_[i](x,true); return CubicInterpolation( this->yBegin_, this->yEnd_, section.begin(), CubicInterpolation::Spline, false, CubicInterpolation::SecondDerivative, 0.0, CubicInterpolation::SecondDerivative, 0.0).derivative(y); }
Real derivativeX(Real x, Real y) const { std::vector<Real> section(this->zData_.columns()); for (Size i=0; i < section.size(); ++i) { section[i] = value(this->xBegin_[i], y); } return CubicInterpolation( this->xBegin_, this->xEnd_, section.begin(), CubicInterpolation::Spline, false, CubicInterpolation::SecondDerivative, 0.0, CubicInterpolation::SecondDerivative, 0.0).derivative(x); }
void MainWindow::on_actionZoom_triggered() { QPixmap oldPixmap = pixmapItem->pixmap(); QImage oldImage = oldPixmap.toImage(); int oldWidth = oldImage.width(); int oldHeight = oldImage.height(); if (oldWidth == 0 || oldHeight == 0) { ui->statusBar->showMessage( tr("Error. Image bad size"), 3000 ); return; } DialogZoom dialog; if (dialog.exec() == QDialog::Rejected) return; double value = dialog.getValue(); int choice = dialog.getChoice(); int width = oldWidth * value; int height = oldHeight * value; QImage image(width, height, QImage::Format_ARGB32); image.fill( QColor(255, 255, 255) ); if (choice == 1) { for (int i = 0; i < width; ++i) for (int j = 0; j < height; ++j) { int srcX = i / value; int srcY = j / value; image.setPixel(i, j, oldImage.pixel(srcX, srcY)); } } else if (choice == 2) { int h, w; double t; double u; double tmp; double d1, d2, d3, d4; QRgb p1, p2, p3, p4; int red, green, blue; for (int j = 0; j < height; ++j) { tmp = j / (double) (height - 1) * (oldHeight - 1); h = qFloor(tmp); h = h < 0? 0: (h >= oldHeight - 1? oldHeight - 2: h); u = tmp - h; for (int i = 0; i < width; ++i) { tmp = i / (double) (width - 1) * (oldWidth - 1); w = qFloor(tmp); w = w < 0? 0: (w >= oldWidth - 1? oldWidth - 2: w); t = tmp - w; d1 = (1 - t) * (1 - u); d2 = t * (1 - u); d3 = t * u; d4 = (1 - t) * u; p1 = oldImage.pixel(w, h); p2 = oldImage.pixel(w + 1, h); p3 = oldImage.pixel(w + 1, h + 1); p4 = oldImage.pixel(w, h + 1); red = (int)(qRed(p1) * d1) + (int)(qRed(p2) * d2) + (int)(qRed(p3) * d3) + (int)(qRed(p4) * d4); blue = (int)(qBlue(p1) * d1) + (int)(qBlue(p2) * d2) + (int)(qBlue(p3) * d3) + (int)(qBlue(p4) * d4); green = (int)(qGreen(p1) * d1) + (int)(qGreen(p2) * d2) + (int)(qGreen(p3) * d3) + (int)(qGreen(p4) * d4); image.setPixel(i, j, qRgb(red, green, blue)); } } } else if (choice == 3) { int scale = qCeil(value); for (int j = scale; j < height - 2 * value; ++j) { // int h = qFloor(j / value); // h = h < 0? 0: (h >= oldHeight - 1? oldHeight - 2: h); for (int i = scale; i < width - 2 * value; ++i) { // int w = qFloor(i / value); // w = w < 0? 0: (w >= oldWidth - 1? oldWidth - 2: w); int srcX = qFloor(i / value); int srcY = qFloor(j / value); double relativeX = (i / value) - qFloor((i / value)); double relativeY = (j / value) - qFloor((j / value)); QRgb p00 = oldImage.pixel(srcX - 1, srcY - 1); QRgb p10 = oldImage.pixel(srcX, srcY - 1); QRgb p20 = oldImage.pixel(srcX + 1, srcY - 1); QRgb p30 = oldImage.pixel(srcX + 2, srcY - 1); QRgb p01 = oldImage.pixel(srcX - 1, srcY); QRgb p11 = oldImage.pixel(srcX, srcY); QRgb p21 = oldImage.pixel(srcX + 1, srcY); QRgb p31 = oldImage.pixel(srcX + 2, srcY); QRgb p02 = oldImage.pixel(srcX - 1, srcY + 1); QRgb p12 = oldImage.pixel(srcX, srcY + 1); QRgb p22 = oldImage.pixel(srcX + 1, srcY + 1); QRgb p32 = oldImage.pixel(srcX + 2, srcY + 1); QRgb p03 = oldImage.pixel(srcX - 1, srcY + 2); QRgb p13 = oldImage.pixel(srcX, srcY + 2); QRgb p23 = oldImage.pixel(srcX + 1, srcY + 2); QRgb p33 = oldImage.pixel(srcX + 2, srcY + 2); double r0 = CubicInterpolation( relativeX, qRed(p00), qRed(p10), qRed(p20), qRed(p30) ); double r1 = CubicInterpolation( relativeX, qRed(p01), qRed(p11), qRed(p21), qRed(p31) ); double r2 = CubicInterpolation( relativeX, qRed(p02), qRed(p12), qRed(p22), qRed(p32) ); double r3 = CubicInterpolation( relativeX, qRed(p03), qRed(p13), qRed(p23), qRed(p33) ); int r = qMax(0.0, qMin(255.0, CubicInterpolation(relativeY, r0, r1, r2, r3))); double g0 = CubicInterpolation( relativeX, qGreen(p00), qGreen(p10), qGreen(p20), qGreen(p30) ); double g1 = CubicInterpolation( relativeX, qGreen(p01), qGreen(p11), qGreen(p21), qGreen(p31) ); double g2 = CubicInterpolation( relativeX, qGreen(p02), qGreen(p12), qGreen(p22), qGreen(p32) ); double g3 = CubicInterpolation( relativeX, qGreen(p03), qGreen(p13), qGreen(p23), qGreen(p33) ); int g = qMax(0.0, qMin(255.0, CubicInterpolation(relativeY, g0, g1, g2, g3))); double b0 = CubicInterpolation( relativeX, qBlue(p00), qBlue(p10), qBlue(p20), qBlue(p30) ); double b1 = CubicInterpolation( relativeX, qBlue(p01), qBlue(p11), qBlue(p21), qBlue(p31) ); double b2 = CubicInterpolation( relativeX, qBlue(p02), qBlue(p12), qBlue(p22), qBlue(p32) ); double b3 = CubicInterpolation( relativeX, qBlue(p03), qBlue(p13), qBlue(p23), qBlue(p33) ); int b = qMax(0.0, qMin(255.0, CubicInterpolation(relativeY, b0, b1, b2, b3))); image.setPixel(i, j, qRgb(r, g, b)); } } } QPixmap pixmap; pixmap.convertFromImage(image); pixmapItem_2->setPixmap(pixmap); scene_2->setSceneRect(QRectF(pixmap.rect())); calcHist(pixmap, hist_2, maxLevel_2); drawHist(pixmapItem_4, hist_2, maxLevel_2); }