parameters: (recist)
return_statement: return polygon.tolist()
docstring: Generate ellipse from RECIST for weakly-supervised segmentation
docstring_summary: Generate ellipse from RECIST for weakly-supervised segmentation
docstring_tokens: Generate ellipse from RECIST for weakly - supervised segmentation
function: def gen_mask_polygon_from_recist(recist):
      """Generate ellipse from RECIST for weakly-supervised segmentation"""
      x11, y11, x12, y12, x21, y21, x22, y22 = recist
      axis1 = np.linalg.solve(np.array([[x11, y11], [x12, y12]]), np.array([1, 1]))
      axis2 = np.linalg.solve(np.array([[x21, y21], [x22, y22]]), np.array([1, 1]))
      center = np.linalg.solve(np.array([[axis1[0], axis1[1]], [axis2[0], axis2[1]]]), np.array([1, 1]))
      centered_recist = recist - np.tile(center, (4,))
      centered_recist = np.reshape(centered_recist, (4, 2))
      pt_angles = np.arctan2(centered_recist[:, 1], centered_recist[:, 0])
      pt_lens = np.sqrt(np.sum(centered_recist ** 2, axis=1))
  
      ord = [0, 2, 1, 3, 0]
      grid = .1
      rotated_pts = []
      for p in range(4):
          # pt1 = centered_recist[ord[p]]
          # pt2 = centered_recist[ord[p+1]]
          if (pt_angles[ord[p]] < pt_angles[ord[p + 1]] and pt_angles[ord[p + 1]] - pt_angles[ord[p]] < np.pi) \
                  or (pt_angles[ord[p]] - pt_angles[ord[p + 1]] > np.pi):  # counter-clockwise
              angles = np.arange(0, np.pi / 2, grid)
          else:
              angles = np.arange(0, -np.pi / 2, -grid)
  
          xs = np.cos(angles) * pt_lens[ord[p]]
          ys = np.sin(angles) * pt_lens[ord[p + 1]]
          r = pt_angles[ord[p]]
          rotated_pts1 = np.matmul(np.array([[np.cos(r), -np.sin(r)], [np.sin(r), np.cos(r)]]),
                                   np.vstack((xs, ys)))
          rotated_pts.append(rotated_pts1)
      rotated_pts = np.hstack(rotated_pts)
      decentered_pts = rotated_pts + center.reshape((2, 1))
      polygon = decentered_pts.transpose().ravel()
      # for p in polygon:
      #     print('%.4f'%p, ',',)
      # print('\n',recist)
      return polygon.tolist()
function_tokens: def gen_mask_polygon_from_recist ( recist ) : x11 , y11 , x12 , y12 , x21 , y21 , x22 , y22 = recist axis1 = np . linalg . solve ( np . array ( [ [ x11 , y11 ] , [ x12 , y12 ] ] ) , np . array ( [ 1 , 1 ] ) ) axis2 = np . linalg . solve ( np . array ( [ [ x21 , y21 ] , [ x22 , y22 ] ] ) , np . array ( [ 1 , 1 ] ) ) center = np . linalg . solve ( np . array ( [ [ axis1 [ 0 ] , axis1 [ 1 ] ] , [ axis2 [ 0 ] , axis2 [ 1 ] ] ] ) , np . array ( [ 1 , 1 ] ) ) centered_recist = recist - np . tile ( center , ( 4 , ) ) centered_recist = np . reshape ( centered_recist , ( 4 , 2 ) ) pt_angles = np . arctan2 ( centered_recist [ : , 1 ] , centered_recist [ : , 0 ] ) pt_lens = np . sqrt ( np . sum ( centered_recist ** 2 , axis = 1 ) ) ord = [ 0 , 2 , 1 , 3 , 0 ] grid = .1 rotated_pts = [ ] for p in range ( 4 ) : # pt1 = centered_recist[ord[p]] # pt2 = centered_recist[ord[p+1]] if ( pt_angles [ ord [ p ] ] < pt_angles [ ord [ p + 1 ] ] and pt_angles [ ord [ p + 1 ] ] - pt_angles [ ord [ p ] ] < np . pi ) or ( pt_angles [ ord [ p ] ] - pt_angles [ ord [ p + 1 ] ] > np . pi ) : # counter-clockwise angles = np . arange ( 0 , np . pi / 2 , grid ) else : angles = np . arange ( 0 , - np . pi / 2 , - grid ) xs = np . cos ( angles ) * pt_lens [ ord [ p ] ] ys = np . sin ( angles ) * pt_lens [ ord [ p + 1 ] ] r = pt_angles [ ord [ p ] ] rotated_pts1 = np . matmul ( np . array ( [ [ np . cos ( r ) , - np . sin ( r ) ] , [ np . sin ( r ) , np . cos ( r ) ] ] ) , np . vstack ( ( xs , ys ) ) ) rotated_pts . append ( rotated_pts1 ) rotated_pts = np . hstack ( rotated_pts ) decentered_pts = rotated_pts + center . reshape ( ( 2 , 1 ) ) polygon = decentered_pts . transpose ( ) . ravel ( ) # for p in polygon: #     print('%.4f'%p, ',',) # print('\n',recist) return polygon . tolist ( )