GradientEnergy::GradientEnergy(QImage& I):image(I) { greyTones(); calculateGradients(); changes = 0; width = image.width(); height = image.height(); mode = FAST; useBlur = false; blurfactor = 1; }
void GradientEnergy::updateH(std::vector<int> seam){ unsigned int* pixs = (unsigned int*)const_cast<unsigned char*>(grey.bits()); for (int i = 0; i < seam.size(); i++){ //move array to remove pixel //TODO for(int y=seam[i];y<height-1;y++) { pixs[i+y*grey.width()]=pixs[i+(y+1)*grey.width()]; } } calculateGradients(); height--; }
//----------------------------------------------------------------------------------------------- // Passes the Jacobian to Bonmin //----------------------------------------------------------------------------------------------- bool BonminInterface::eval_jac_g(Index n, const Number* x, bool new_x, Index m, Index nele_jac, Index* iRow, Index *jCol, Number* values) { // checking if the structure of the jacobian has been set if (values == NULL) { cout << "Giving bonmin the structure of the jacobian..." << endl; int entry = 0; for ( int col = 0; col < n; col++ ) { for ( int row = 0; row < m; row++) { iRow[entry] = row; jCol[entry] = col; entry++; } } } else // the structure is already set, getting the values { //cout << "Evaluating the jacobian for bonmin..." << endl; // checking if gradients are calculated if(!gradientsAreUpdated(n,x)) { calculateGradients(n,x); } // copying gradients to BonMin for(int i = 0; i < nele_jac; i++) { values[i] = m_jac_g.at(i); } } return true; }
void GradientEnergy::updateV(std::vector<int> seam){ unsigned int* pixs = (unsigned int*)const_cast<unsigned char*>(grey.bits()); for (int i = 0; i < seam.size(); i++){ //move array to remove pixel for(int x=seam[i];x<width-1;x++) { pixs[x+i*grey.width()]=pixs[x+1+i*grey.width()]; } } /*if(changes >= 2){ //std::clock_t t = std::clock(); calculateGradients(); //t = std::clock() - t; //qDebug()<<"TIME: "<<((float)t)/CLOCKS_PER_SEC; changes = 0; } changes++;*/ calculateGradients(); width--; }
//----------------------------------------------------------------------------------------------- // Calculates the derivatives of the objective //----------------------------------------------------------------------------------------------- bool BonminInterface::eval_grad_f(Index n, const Number* x, bool new_x, Number* grad_f) { // cout << "Evaluating the gradient for bonmin..." << endl; // first checking if gradients are allready calculated if(!gradientsAreUpdated(n,x)) { cout << "need to calculate new gradients..." << endl; calculateGradients(n,x); cout << "done calculating new gradients..." << endl; } // copying the calculated gradients to BonMin for(int i = 0; i < n; i++) { grad_f[i] = m_grad_f.at(i); // cout << "grad_f[" << i << "] = " << grad_f[i] << endl; } return true; }
void canny(FILE* inputImageFile, FILE* outputMagnitudes, FILE* outputPeaks, FILE* outputFinal, double sigma){ Mask mask; int picBuffer[PICSIZE][PICSIZE]; double itsMagnitudes[PICSIZE][PICSIZE]; double maxMagnitude; GradientVector usingGradients; double peaks[PICSIZE][PICSIZE]; double final[PICSIZE][PICSIZE]; readImageTo(picBuffer, inputImageFile); mask = generateSmoothenerMask(sigma); usingGradients = calculateGradients(picBuffer, mask); calculateMagnitudes(usingGradients, mask.radius, itsMagnitudes); maxMagnitude = findMaxValue(itsMagnitudes); scaleImageWithRespectTo(maxMagnitude, itsMagnitudes); findPeaks(itsMagnitudes, usingGradients, mask.radius, peaks); Threshold threshold = getThreshold(itsMagnitudes); applyHysteresisThresholdTo(itsMagnitudes, usingGradients, mask.radius, peaks, threshold, final); writeTo(outputMagnitudes, itsMagnitudes); writeTo(outputPeaks, peaks); writeTo(outputFinal, final); }