Seam Carving

Only available on StudyMode
  • Pages : 4 (960 words )
  • Download(s) : 49
  • Published : May 2, 2013
Open Document
Text Preview
#operating only in the Y domain

from numpy import *
from scipy import *
import os
from datetime import datetime
print datetime.time(datetime.now())
def find_path(X):
C=arange(row*col).reshape(row,col)
pix=0
for i in range (1,(row-1)):
for j in range (1,(col-1)):
pix=X[i][j]
C[i][j]=abs(pix-X[i-1][j-1])+abs(pix-X[i-1][j])+abs(pix-X[i-1][j+1])+abs(pix-X[i][j+1])+abs(pix-X[i+1][j+1])+abs(pix-X[i+1][j])+abs(pix-X[i+1][j-1])+abs(pix-X[i][j-1]) for j in range (1,(col-1)):

pix=X[0][j]
C[0][j]=abs(pix-X[0][j-1])+abs(pix-X[1][j-1])+abs(pix-X[1][j])+abs(pix-X[1][j+1])+abs(pix-X[0][j+1]) pix=X[row-1][j]
C[row-1][j]=abs(pix-X[row-1][j-1])+abs(pix-X[row-2][j-1])+abs(pix-X[row-2][j])+abs(pix-X[row-2][j+1])+abs(pix-X[row-1][j+1]) for i in range (1,(row-1)):
pix=C[i][0]
C[i][0]=abs(pix-X[i-1][0])+abs(pix-X[i-1][1])+abs(pix-X[i][1])+abs(pix-X[i+1][1])+abs(pix-X[i+1][0]) pix=C[i][col-1]
C[i][col-1]=abs(pix-X[i-1][col-1])+abs(pix-X[i-1][col-2])+abs(pix-X[i][col-2])+abs(pix-X[i+1][col-2])+abs(pix-X[i+1][col-1]) C[0][0]=abs(X[0][0]-X[1][0])+abs(X[0][0]-X[1][1])+abs(X[0][0]-X[0][1]) C[0][col-1]=abs(X[0][col-1]-X[0][col-2])+abs(X[0][col-1]-X[1][col-2])+abs(X[0][col-1]-X[1][col-1]) C[row-1][0]=abs(X[row-1][0]-X[row-2][0])+abs(X[row-1][0]-X[row-2][1])+abs(X[row-1][0]-X[row-1][1]) C[row-1][col-1]=abs(X[row-1][col-1]-X[row-2][col-1])+abs(X[row-1][col-1]-X[row-1][col-2])+abs(X[row-1][col-1]-X[row-2][col-2]) M=arange(row*col).reshape(row,col)

M[::]=0
for j in range (0,col):
M[0][j]=C[0][j]
for i in range (1,row):
for j in range (0,col):
if j==0:
M[i][j]=C[i][j]+min(M[i-1][j],M[i-1][j+1])
elif j==(col-1):
M[i][j]=C[i][j]+min(M[i-1][j],M[i-1][j-1])
else:
min_val=min(M[i-1][j-1],M[i-1][j])...
tracking img