augmentation.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:Triplet_Loss_SBIR 作者: TuBui 项目源码 文件源码
def edge_rotate(im,ang):
  """
  rotate edge map using nearest neighbour preserving edge and dimension
  Assumption: background 255, foreground 0
  currently does not work as good as ndimage.rotate
  """
  ang_rad = np.pi / 180.0 * ang
  H,W = np.float32(im.shape)
  R = mat([[np.cos(ang_rad),-np.sin(ang_rad) ,0],
        [np.sin(ang_rad), np.cos(ang_rad),0],
        [0              ,0               ,1.0]])
  T0 = mat([[1.0,0,-W/2],[0,1.0,-H/2],[0,0,1.0]])
  M0 = T0.I * R * T0

  tl_x,tl_y = np.floor(warping([0,0],M0))
  tr_x,tr_y = np.floor(warping([W-1,0],M0))
  bl_x,bl_y = np.floor(warping([0,H-1],M0))
  br_x,br_y = np.floor(warping([W-1,H-1],M0))

  minx = np.min([tl_x,tr_x,bl_x,br_x])
  maxx = np.max([tl_x,tr_x,bl_x,br_x])
  miny = np.min([tl_y,tr_y,bl_y,br_y])
  maxy = np.max([tl_y,tr_y,bl_y,br_y])
  T1 = mat([[1.0,0.0,minx],
            [0.0,1.0,miny],
            [0.0,0.0,1.0]])
  M1 = M0.I * T1
  nW = int(maxx - minx+1)
  nH = int(maxy - miny+1)

  out = np.ones((nH,nW),dtype=np.float32)*255
  for y in xrange(nH):
    for x in xrange(nW):
      u,v = np.int64(warping([x,y],M1))
      if u>=0 and u<W and v>=0 and v<H and im[v,u]!=255:
        out[y,x]=0

  return out
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号