Esempio n. 1
0
def plot_grey_level_image(data, time_period, y_title, title):
    x = data[:, 12].astype(float)
    image_array = np.zeros((time_period, 1400))
    for i in range(len(x)):
        day = int(x[i])
        second = int(time_period * (x[i] - math.floor(x[i])))
        if second >= time_period:
            second = time_period - 1
        image_array[second, day] += 1

    print "max(image_array.flatten()):", max(image_array.flatten())
    plot_hist(image_array, title)
    image_array = (255.0 / 31.0) * image_array
    binary_image = assignment2_p1.get_binary_image(image_array,
                                                   threshold=5,
                                                   low_threshold_indi=False,
                                                   title=title)
    if image_inverse:
        image_array = 255.0 - image_array
        binary_image = 255.0 - binary_image
    plt.imshow(image_array, cmap='gray')
    plt.title(title)
    plt.ylabel(y_title)
    plt.xlabel("Days since 2011 January 1")
    plt.savefig('/home/tingxu/Documents/jimmy/tw5cities/output/' + title +
                '.png')
    plt.imshow(binary_image, cmap='gray')
    plt.title(title + " with data argument")
    plt.ylabel(y_title)
    plt.xlabel("Days since 2011 January 1")
    plt.savefig('/home/tingxu/Documents/jimmy/tw5cities/output/' + title +
                'binary.png')
    plt.show()
def plot_grey_level_image(data, time_period, y_title, title):
    x = data[:, 12].astype(float)
    image_array = np.zeros((time_period, 1400))
    for i in range(len(x)):
        day = int(x[i])
        second = int(time_period * (x[i] - math.floor(x[i])))
        if second >= time_period:
            second = time_period - 1
        image_array[second, day] += 1
    image_array_active_ratio = np.zeros(image_array.shape)
    image_array_active_ratio.astype(float)
    print "max(image_array.flatten()):", max(image_array.flatten())
    plot_hist(image_array, title)
    for i in range(len(image_array)):
        for j in range(len(image_array[0])):
            if sum(image_array[:, j]) > 1.0:
                image_array_active_ratio[i,
                                         j] = 1000.0 * image_array[i, j] / sum(
                                             image_array[:, j])
    image_array = (255.0 / 120.0) * image_array
    #plot_hist(image_array,title+'adjusted')
    binary_image = assignment2_p1.get_binary_image(image_array_active_ratio,
                                                   threshold=1000.0 * 0.01,
                                                   low_threshold_indi=False,
                                                   title=title)
    if image_inverse:
        image_array = 255.0 - image_array
        binary_image = 255.0 - binary_image
    plt.imshow(image_array, cmap='gray')
    plt.title(title)
    plt.ylabel(y_title)
    plt.xlabel("Days since 2011 January 1")
    plt.savefig('/home/tingxu/Documents/jimmy/tw5cities/output/' + title +
                '.png')
    #binary_image=assignment2_p1.get_binary_image(image_array,threshold=10,low_threshold_indi=False,title=title)
    plt.imshow(binary_image, cmap='gray')
    plt.title(title + "active timeline")
    plt.ylabel(y_title)
    plt.xlabel("Days since 2011 January 1")
    plt.savefig('/home/tingxu/Documents/jimmy/tw5cities/output/' + title +
                'binary.png')
    plt.show()