def main():
    fo = sys.argv[1]
    fk = path.join("out/r0_KMeansThresholding",path.basename(f0))
    r = int(getarg(2,0))
    inname = getarg(3,"data/r%d_lin.p" % (r))

    print("Test with radius=%d and file %s and model %s" % (r,f,inname))

    model = pickle.load(open(inname, "rb"))

    w,h = Image.open(f).size
    X = extract_x([fo],r)
    Xk = extract_x([fk],r,True)
    X = np.concatenate([X,Xk], axis=1)

    dim = (h-2*r,w-2*r)
    y = model.predict(X)
    y = np.reshape(y, dim)
    y = denormalize(y)

    if(np.any(np.isnan(y))):
        print("result of",f, "has nan values after denormalizing")

    img = Image.fromarray(y.astype(np.uint8))
    outfold = str.replace(str.replace(inname,".p",""),"data/","out/")
    outf = path.join(outfold,path.basename(f))
    mkdir_p(outfold)
    img.save(outf)
def main():
    r = int(getarg(1, 0))
    k = int(getarg(2, 3))

    print("Extracting with radius=%d" % (r))

    prefix = "data/train"
    outname = prefix+"_c_k"+str(k)+"_r"+str(r)+".npz"
    print("Saving to: "+ outname)

    train_files_x = find_files(prefix)
    X = extract_x(train_files_x,r)
    Xk = extract_x(find_files(prefix+"_k"+str(k)),r,True)
    X = np.concatenate([X,Xk], axis=1)

    train_files_y = find_files("data/train_cleaned")
    y = extract_y(train_files_y,r)

    np.savez(outname,X=X,y=y)
def main():
    test_files = find_files("data/test")
    model = pickle.load(open("data/raw_lin.p", "rb"))
    for f in test_files:
        w,h = Image.open(f).size
        X = extract_x([f])
        y = np.reshape(model.predict(X), (h,w))
        y = np.vectorize(filter_point_value)(y)

        img = Image.fromarray(y.astype(np.uint8))
        outf = str.replace(f,"data/test","out/raw_lin")
        img.save(outf)
def main():
    model = KMeansThresholding()
    
    train_files_x = find_files("data/train")
    train_files_y = find_files("data/train_cleaned")

    y_pred = map(lambda x: extract_x([x],0), train_files_x)
    y_pred = list(map(predict, y_pred))
    y_pred = np.concatenate(y_pred)

    y_true = np.concatenate(list(map(lambda x: extract_y([x],0) ,train_files_y)))

    print("Calculating MSE")

    mse =  metrics.mean_squared_error(y_true, y_pred)
    print("MSE: %0.2f (+/- %0.2f)" % (mse.mean()*100, mse.std() * 200))
def main():
    r = int(getarg(1, 0))
    k = int(getarg(2, 0))

    print("Extracting with radius=%d" % (r))

    prefix = "data/train"
    if(k > 0):
        prefix += "_k"+str(k)

    train_files_x = find_files(prefix)
    X = extract_x(train_files_x,r)

    train_files_y = find_files("data/train_cleaned")
    y = extract_y(train_files_y,r)

    outname = prefix+"_r"+str(r)+".npz"
    np.savez(outname,X=X,y=y)