def returnSquaredErrors(fname=None, div=None, size=None):
    if fname == None:
        #fname = 'centerlines/t250_half_sup_straight_seg_centerline.nii.gz'
        fname = 't234_crop_200_500_straight_centerline.nii.gz'
    file = nibabel.load(fname)
    data = file.get_data()
    p1, p2, p3 = splinap.getPxDimensions(fname)
    nx, ny, nz = splinap.getDim(fname)
    #os.remove(fname)



    print 'sizes: ', nx, ny, nx
    #x, y, x_fit, y_fit = fit(data, nz)

    '''
    print x, y, z
    fig1 = plt.figure()
    ax = Axes3D(fig1)
    ax.plot(x,y,z,'b:',zdir='z')
    plt.show()
    '''

    X,Y,Z = (data>0).nonzero()

    zmin = min(Z) + 10
    zmax = max(Z) - 10

    print "min value element : ", zmin
    print "max value element : ", zmax

    nz = zmax - zmin

    x = [0 for iz in range(0, nz, 1)]
    y = [0 for iz in range(0, nz, 1)]
    z = [iz for iz in range(0, nz, 1)]


    for iz in range(0, nz, 1):
        x[iz], y[iz] = ndimage.measurements.center_of_mass(np.array(data[:,:,iz + zmin]))


    x_fit,y_fit = get_good_centerline(nx, ny, nz)


    msx = mean_squared_error(x, x_fit)
    msy = mean_squared_error(y, y_fit)
    mean_ms = (msx+msy)/2

    #print x, x_fit
    #print y, y_fit

    fig1 = plt.figure()
    ax = Axes3D(fig1)
    ax.plot(x,y,z,zdir='z')
    ax.plot(x_fit,y_fit,z,zdir='z')
    plt.show()


    print msx, msy, mean_ms
    size_crop = splinap.getSize(x, y, z, p1, p2, p3)


    txt = open('results.txt', 'a')
    txt.write(str(div)+' '+str(div/int(round(size)))+' '+str(size_crop)+' '+str(size)+' '+str(msx)+' '+str(msy)+' '+' '+str(mean_ms)+' '+fname+'\n')
    #txt.write(' plynomial_fitting '+str(size_crop)+' '+str(size)+' '+str(msx)+' '+str(msy)+' '+' '+str(mean_ms)+' '+fname+'\n')


    txt.close()

    #splinap.plot(x_fit,y_fit, z, x, y, z, fname, int(round(size))/div)
dataset/ETHPy150Open neuropoly/spinalcordtoolbox/dev/control_points/linear_fitting.py/returnSquaredErrors/swapped operands of `/`