Advertisement
Guest User

Seam Carving

a guest
Nov 1st, 2014
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. //THIS IS TO FORM THE THIRD GRID(from the energy grid)
  2. //this is the grid you use to calculate what your vertical seam's path is
  3. //from top to bottom
  4.  
  5. //push back our initial row
  6. //The First Row of Your Energy Grid
  7.     for (int i = 0; i < Columns; ++i){
  8.         DynamicSums[0].push_back(Weighted[0][i]);
  9.     }
  10.  
  11.     for (int i = 1; i < Rows; ++i){
  12.         DynamicSums.push_back(emptyVector);
  13.         for (int j = 0; j < Columns; ++j){
  14.             CurrentMin = -1;
  15.            
  16.             if (j - 1 >= 0){//check if we can go up and left
  17.                 CurrentMin = Weighted[i][j] + DynamicSums[i - 1][j - 1];
  18.             }
  19.            
  20.             if (CurrentMin == -1){//case where you are on left wall of grid
  21.                 CurrentMin = Weighted[i][j] + DynamicSums[i - 1][j];
  22.             }
  23.             else{
  24.                 CurrentMin = min(CurrentMin, Weighted[i][j] + DynamicSums[i - 1][j]);
  25.             }
  26.  
  27.             if (j + 1 < Columns){//check if we can go up and right
  28.                 CurrentMin = min(CurrentMin, Weighted[i][j] + DynamicSums[i - 1][j + 1]);
  29.             }
  30.  
  31.             DynamicSums[i].push_back(CurrentMin);
  32.         }
  33.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement