def save_curves_matlab(filename, artist, dir, curves, shape):
    util.DW("%s/%s" % (dir, artist))
    f = open("%s/%s/%s_MATLAB_POINTS.m" % (dir, artist, filename), 'w')

    curve_counter = 0
    for curve in curves:
        curve_counter += 1

        x_list = []
        y_list = []
        for p in curve:
            x_list.append(p.y)
            y_list.append(-p.x)
        f.write("x%d = %s;\n" % (curve_counter, x_list))
        f.write("y%d = %s;\n" % (curve_counter, y_list))

    f.write("\nplot(")
    for i in xrange(1, curve_counter + 1):
        f.write("x%d, y%d, " % (i, i))
    f.write("'LineWidth', 2),\n")
    f.write("axis([%d %d %d %d]),\n" % (0, shape[1], -shape[0], 0))
    f.write("title('%s'), grid on;\n" % filename)
    f.write(
        "filename = '\Users\PJF\PycharmProjects\cv_projects\\vectorized\%s\%s_POINTS.png';\n"
        % (artist, filename))
    f.write("saveas(gcf,filename)")

    f.close()
def save_curves_matlab_natural_spline(filename, artist, dir, curves, shape):
    util.DW("%s/%s" % (dir, artist))
    f = open("%s/%s/%s_MATLAB_NATURAL.m" % (dir, artist, filename), 'w')

    curve_counter = 0
    idx = []
    for curve in curves:

        if len(curve) < 2: continue
        curve_counter += 1

        x_list = []
        y_list = []
        for p in curve:
            x_list.append(p.y)
            y_list.append(-p.x)

        # REMOVE DUPLICATES
        prev_x = 0
        new_x = []
        new_y = []
        for i in xrange(len(x_list)):
            if abs(x_list[i] - prev_x) > 0.001:
                new_x.append(x_list[i])
                new_y.append(y_list[i])
                prev_x = x_list[i]

        x_list = new_x
        y_list = new_y

        if len(new_x) < 2:
            curve_counter -= 1
            continue

        f.write("pts%d = [" % curve_counter)
        for x in x_list[:-1]:
            f.write("%f," % x)
        f.write("%f; " % x_list[-1])

        for y in y_list[:-1]:
            f.write("%f," % y)
        f.write("%f];\n " % y_list[-1])

        f.write("cs%d = cscvn(pts%d);\n" % (curve_counter, curve_counter))
        idx.append(curve_counter)

    for i in idx:
        if len(curves[i - 1]) < 2: continue
        f.write("fnplt(cs%d, 2)\n" % i)
        f.write("hold on\n")
    f.write("axis([%d %d %d %d]),\n" % (0, shape[1], -shape[0], 0))
    f.write("title('%s'), grid on;\n" % filename)
    f.write(
        "filename = '\Users\PJF\PycharmProjects\cv_projects\\vectorized\%s\%s_NATURAL.png';\n"
        % (artist, filename))
    f.write("saveas(gcf,filename)")

    f.close()
def save_curves_matlab_smoothing_spline(filename, artist, dir, curves, shape):
    util.DW("%s/%s" % (dir, artist))
    f = open("%s/%s/%s_MATLAB_SMOOTHING.m" % (dir, artist, filename), 'w')

    curve_counter = 0
    idx = []
    for curve in curves:

        #print("Curve length: %d" % len(curve))
        if len(curve) < 2: continue
        curve_counter += 1

        x_list = []
        y_list = []
        for p in curve:
            x_list.append(p.y)
            y_list.append(-p.x)

        # REMOVE DUPLICATES
        prev_x = 0
        new_x = []
        new_y = []
        for i in xrange(len(x_list)):
            if abs(x_list[i] - prev_x) > 0.001:
                new_x.append(x_list[i])
                new_y.append(y_list[i])
                prev_x = x_list[i]

        x_list = new_x
        y_list = new_y

        if len(new_x) < 2:
            curve_counter -= 1
            continue

        f.write("x%d = %s;\n" % (curve_counter, x_list))
        f.write("y%d = %s;\n" % (curve_counter, y_list))
        f.write("cs%d = csaps(x%d, y%d, 0.5);\n" %
                (curve_counter, curve_counter, curve_counter))
        idx.append(curve_counter)

    for i in idx:
        if len(curves[i - 1]) < 2: continue
        f.write("fnplt(cs%d, 2)\n" % i)
        f.write("hold on\n")
    f.write("axis([%d %d %d %d]),\n" % (0, shape[1], -shape[0], 0))
    f.write("title('%s'), grid on;\n" % filename)
    f.write(
        "filename = '\Users\PJF\PycharmProjects\cv_projects\\vectorized\%s\%s_SMOOTHING.png';\n"
        % (artist, filename))
    f.write("saveas(gcf,filename)")

    f.close()
コード例 #4
0
    ]
    images = [
        'test2', 'levesque2', 'koudelka5', 'vidal2', 'fiala_001', 'fiala_010',
        'levesque1', 'vidal6', 'fiala_014', 'test1'
    ]

    artists = ['fiala']
    images = ['fiala_001']

    for i in xrange(len(images)):
        artist = artists[i]
        img_name = images[i]
        orig_name = img_name

        # Load a color image in grayscale
        img = cv2.imread("samples/%s/%s.jpg" % (artist, img_name), 0)
        util.display_img(img, "Initial Image", DISPLAY_IMG)

        img_name = orig_name + "_SCARCE"

        print("Clustering %s, %s" % (artist, img_name))
        util.DW("pixelClustering/%s/%s" % (artist, img_name))
        util.DW("pointSet/%s" % artist)
        util.DW("stats/%s" % artist)

        f = open(
            "%s/%s/%s_pixelClustering_NEW.txt" % ("stats", artist, img_name),
            'w')
        moving_points = get_cluster_points(f, img, img.shape, img_name, artist)
        f.close()
コード例 #5
0
        corners = np.int0(corners)

        tmp = img.copy()
        tmp = cv2.cvtColor(tmp, cv2.COLOR_GRAY2BGR)
        for corner in corners:
            x, y = corner.ravel()
            cv2.circle(tmp, (x, y), 3, (0, 255, 0), -1)

        moving_points, point_map = util.load_point_map("%s.txt" % img_name,
                                                       artist, "pointSet",
                                                       img.shape)

        img_name = img_name + "_PR_NBHD"

        cv2.imwrite(
            "topology/%s/%s/%s_CORNERS_orig.jpg" %
            (artist, img_name, img_name), tmp)

        print("Extracting Topology for %s, %s" % (artist, img_name))
        util.DW("curves/%s" %
                artist)  # I think you only need this in a next step...
        util.DW("topology/%s/%s" % (artist, img_name))
        util.DW("stats/%s" % artist)
        util.DW("buddyPoints/%s" % artist)

        f = open("%s/%s/%s_topology.txt" % ("stats", artist, img_name), 'w')
        extract_topology(f, moving_points, point_map, img.shape, corners)
        f.close()

        cv2.destroyAllWindows()
コード例 #6
0
for i in xrange(len(images)):

    artist = artists[i]
    img_name = images[i]

    print("Vectorizing %s" % img_name)

    # Load a color image in grayscale
    img = cv2.imread("samples/%s/%s.jpg" % (artist, img_name), 0)
    util.display_img(img, "Initial Image", False)

    img_name += "_170421_FINAL"

    # ensure that required directories are created
    util.DW("pixelClustering/%s/%s" % (artist, img_name))
    util.DW("pointSet/%s" % artist)
    util.DW("stats/%s" % artist)
    util.DW("curves/%s" %
            artist)  # I think you only need this in a next step...
    util.DW("topology/%s/%s" % (artist, img_name))
    util.DW("buddyPoints/%s" % artist)
    util.DW("smoothing/%s/%s" % (artist, img_name))
    util.DW("vectorized/%s" % artist)

    f = open("%s/%s/%s_FULL.txt" % ("stats", artist, img_name), 'w')
    """ VECTORIZATION PROCESS """

    start_time = time.time()

    # PIXEL CLUSTERING
    images = ['vidal6']

    for i in xrange(len(images)):
        artist = artists[i]
        img_name = images[i]

        print("Curve Fitting for %s, %s" % (artist, img_name))

        # Load a color image in grayscale
        img = cv2.imread("samples/%s/%s.jpg" % (artist, img_name), 0)
        util.display_img(img, "Initial Image", DISPLAY_IMG)

        img_name += "_PR_NBHD"

        #img_name += "_LSW"
        util.DW("smoothing/%s/%s" % (artist, img_name))
        util.DW("vectorized/%s" % artist)

        f = open("%s/%s/%s_smoothing.txt" % ("stats", artist, img_name), 'w')

        curves = util.load_curves("%s.txt" % img_name, artist, "curves")

        img_name += "_WHAT"

        mfc.save_matlab_suite("%s_MESSY" % img_name, artist, "curves", curves,
                              img.shape)
        f.write("Number of curves: %d\n" % len(curves))

        smooth_image(f, curves)

        f.close()