Skip to content

Instantly share code, notes, and snippets.

@jschwinger233
Created April 25, 2014 14:10
Show Gist options
  • Save jschwinger233/11290890 to your computer and use it in GitHub Desktop.
Save jschwinger233/11290890 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 26 19:36:04 2014
@author: Administrator
"""
import heapq
import numpy as np
from scipy.misc import imread
import matplotlib.pyplot as plt
import sys
sys.path.extend('F:\\点我,就是我\\cumcm2013\\附件3')
n, h, w = 209, 180, 72
pic = np.array([imread('%03d.bmp' % i) for i in xrange(n)], dtype=np.uint8)
cap = np.zeros((5*n+2, 5*n+2), dtype=np.uint8)
cost = np.zeros((5*n+2, 5*n+2), dtype=np.uint32)
par = np.arange(1, 5*n+1, 5).reshape((-1, 1))
sin = np.arange(2, 5*n+1, 5).reshape((-1, 1)) + np.arange(2)
sout = np.arange(4, 5*n+1, 5).reshape((-1, 1)) + np.arange(2)
cap[sin, par] = 1
cap[par, sout] = 1
cap[0, sin] = 1 # s to in
cap[sout, -1] = 1 # out to t
cap[sout, sin] = 1
for i in xrange(n):
cost[5*i+4, 2:-1:5] = np.sum((pic[i, -1] - pic[:, 0]) ** 2, axis=1)
cost[5*i+4, 3:-1:5] = np.sum((pic[i, :, -1] - pic[:, :, 0]) ** 2, axis=1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment