Advertisement
Guest User

Untitled

a guest
Jul 9th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Select a certain number of horizontal seams and remove them...
  2.         for( int vSeams = 0; vSeams < difWid; vSeams++ ){
  3.             //Create and calculate the seam values
  4.             //Set the first row of seam values equal to the energies at those points.
  5.             double *seamMap = new double [ (inWid-vSeams)*outHei ]; ////you space params, but not for complex index selectors?
  6.             for( int col = 0; col < inWid-vSeams; col++ ){
  7.                 seamMap[col] = energy[col];
  8.             }
  9.  
  10.             //For every subsequent row, set each pixel's seam value equal to the sum of its energy and the least of all the top neighbor's energies.
  11.             for( int row = 1; row < outHei ; row++ ){
  12.                 for( int col = 0; col < inWid-vSeams; col++ ){
  13.                     seamMap[ row*(inWid-vSeams) + col ] = energy[ row*inWid + col ]
  14.                                                       + minOfThree( getArBd(row-1,col-1,inWid-vSeams,outHei,seamMap,maxEnergy*outHei),
  15.                                                                      getArBd(row-1,col  ,inWid-vSeams,outHei,seamMap,maxEnergy*outHei),
  16.                                                                      getArBd(row-1,col+1,inWid-vSeams,outHei,seamMap,maxEnergy*outHei));
  17.                 }
  18.             }
  19.  
  20.             //Store each column index for every row, starting from last and working backward. This way we can easily get each pixel of the seam.
  21.             int *colIndicies = new int [outHei];
  22.  
  23.             //Find lowest value seam ending by looking at ending columns and finding lowest cumulative seam.
  24.             colIndicies[outHei-1] = 0;
  25.             double minSeam = getArBd( outHei-1, 0, inWid-vSeams, outHei, seamMap, maxEnergy*outHei );
  26.             for( int col = 1; col < inWid-vSeams; col++ ){
  27.                 double current = getArBd( outHei-1, col, inWid-vSeams, outHei, seamMap, maxEnergy*inWid );
  28.                 if( current < minSeam ){
  29.                     minSeam = current;
  30.                     colIndicies[outHei-1] = col;
  31.                 }
  32.             }
  33.            
  34.             //Work from ending to recover entire least important seam.
  35.             for( int row = outHei - 2; row >= 0; row -- ){
  36.                 double a = getArBd( row, colIndicies[row+1]-1, inWid-vSeams, outHei, seamMap, maxEnergy*outHei ),
  37.                     b = getArBd( row, colIndicies[row+1]  , inWid-vSeams, outHei, seamMap, maxEnergy*outHei ),
  38.                     c = getArBd( row, colIndicies[row+1]+1, inWid-vSeams, outHei, seamMap, maxEnergy*outHei );
  39.                 double min = minOfThree( a, b, c );
  40.                
  41.                 colIndicies[row] =
  42.                     min == a ? colIndicies[row+1]-1 :
  43.                         min == b ? colIndicies[row+1] :
  44.                             colIndicies[row+1]+1;////i herd u liek ternary so i put a ternary in ur ternary.
  45.                             ////this does the same thing with half the characters.
  46.             }
  47.  
  48.             //Call shift function on the seam point of each column of image and energy; get rid of that seam in the image and in energy map
  49.             for( int row = 0; row < outHei; row ++ ){
  50.                 shift( row, colIndicies[row], inWid-vSeams, outHei, inWid, false, image );
  51.                 shift( row, colIndicies[row], inWid-vSeams, outHei, inWid, false, energy );
  52.             }
  53.  
  54.             //Recompute the energy at the locations where the seam was removed, and at the locations exactly below that
  55.             for( int row = 0; row < outHei; row ++ ){
  56.                 for( int dif = -2; dif <= 2; dif ++ ){
  57.                     int index = colIndicies[row] + dif;
  58.                     if( index >= 0 && index < inWid-vSeams ){ ////unnessisary brackets around inWid-vSeams that weren't elsewhere...
  59.                         energy[row*inWid + index] = computeEnergy( row, index, inWid-vSeams-1, outHei, inWid, image );
  60.                     }
  61.                 }
  62.             }
  63.  
  64.             delete [] colIndicies;
  65.             delete [] seamMap;
  66.         }
  67.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement