コード例 #1
0
def main():
    '''Demo blob finding in grain image.'''
    # Load and show
    img = imread('img/104_E5R_0.jpg')
    img = rgb2gray(img)
    show_with_hist(img, 'Original image')

    # Get temperature bounds
    print(get_temperature_bounds(img))

    # Crop
    img_crop = crop_ui(img)
    show_with_hist(img_crop, 'Cropped image')

    # Invert
    img_inv = invert(img_crop)
    show_with_hist(img_inv, 'Inverted')

    img_prep = img_inv

    blobs = find_blobs(img_prep)

    _, ax = plt.subplots(1)
    plt.title("blobs detection with DoH")
    plt.imshow(img_crop, cmap=plt.get_cmap('gray'))
    for blob in blobs:
        y, x, r = blob
        c = plt.Circle((x, y), r, color='r', linewidth=0.75, fill=False)
        ax.add_patch(c)
    ax.set_axis_off()
    print(len(blobs))
コード例 #2
0
def grain_samples_imgs_gen():
    samples_names = ('104_E5R', '117_E6R')
    for name in samples_names:
        imgs = load_img_series('img/' + name)
        for i, img in enumerate(imgs):
            img = rgb2gray(img)
            imsave('exports/' + name + '_' + str(i) + '.png',
                   img_as_ubyte(crop_ui(img)))
コード例 #3
0
def blob_detection_compare_plots_gen():
    img = imread('img/104_E5R_0.jpg')
    img_crop = crop_ui(rgb2gray(img))
    img_prep = full_prepare(img)
    blobs_list = compare_detection(img_prep)

    suffixes = ('LoG', 'DoG', 'DoH')

    for blobs, suffix in zip(blobs_list, suffixes):
        _, ax = plt.subplots()
        plt.title('Liczba wykrytych detali: {}'.format(len(blobs)))
        plt.imshow(img_crop, cmap=plt.get_cmap('gray'))
        for blob in blobs:
            y, x, r = blob
            c = plt.Circle((x, y), r, color='r', fill=False)
            ax.add_patch(c)

        ax.set_axis_off()
        tikzplotlib.save('exports/blob_detection_compare_' + suffix)
コード例 #4
0
def blob_count_plots_gen():
    imgs = load_img_series('img/104_E5R')
    imgs_prep = [full_prepare(img) for img in imgs]
    imgs_crop = [crop_ui(rgb2gray(img)) for img in imgs]

    stages_all = find_blob_series(imgs_prep, only_remaining=False)
    stages_rem = find_blob_series(imgs_prep)

    # Map stages on first image
    colors = ('blue', 'blueviolet', 'magenta', 'crimson', 'red')
    fig = plt.figure(frameon=False)
    ax = fig.add_axes([0, 0, 1, 1])
    plt.imshow(imgs_crop[0], cmap=plt.get_cmap('gray'))
    for stage, color in zip(stages_rem, colors):
        for blob in stage:
            y, x, r = blob
            c = plt.Circle((x, y), r, color=color, fill=False)
            ax.add_patch(c)
    ax.set_axis_off()
    plt.savefig('exports/blob_tracker', dpi=300)

    # Show two methods combined to compare
    loop_set = enumerate(zip(stages_rem, stages_all, imgs_crop))
    for i, (stage_rem, stage_all, img) in loop_set:
        fig = plt.figure(frameon=False)
        ax = fig.add_axes([0, 0, 1, 1])
        plt.imshow(img, cmap=plt.get_cmap('gray'))
        for blob_all in stage_all:
            y, x, r = blob_all
            c = plt.Circle((x, y), r, color='b', fill=False)
            ax.add_patch(c)
        for blob_rem in stage_rem:
            y, x, r = blob_rem
            c = plt.Circle((x, y), r, color='r', fill=False)
            ax.add_patch(c)

        ax.set_axis_off()
        plt.savefig('exports/blob_tracker_min_' + str(i))
コード例 #5
0
def main():
    '''Demo blob tracking with various ways of counting blobs.'''
    # Load images
    imgs = load_img_series('img/104_E5R')
    # Prepare images for processing
    imgs_prep = [full_prepare(img) for img in imgs]
    # Prepare cropped images for displaying
    imgs_crop = [crop_ui(rgb2gray(img)) for img in imgs]

    # Find blobs for stages of cooling with preserving only remainig ones
    stages_rem = find_blob_series(imgs_prep)

    # Map stages on first image
    colors = ('blue', 'blueviolet', 'magenta', 'crimson', 'red')
    _, ax = plt.subplots(1)
    plt.title("Blobs detection with DoH")
    plt.imshow(imgs_crop[0], cmap=plt.get_cmap('gray'))
    for stage, color in zip(stages_rem, colors):
        for blob in stage:
            y, x, r = blob
            c = plt.Circle((x, y), r, color=color, linewidth=0.75, fill=False)
            ax.add_patch(c)
    labels = ('Minute 0', 'Minute 1', 'Minute 2', 'Minute 3', 'Minute 4')
    patch_plot_legend_outside(colors, labels)
    print(ratio_of_remaining_blobs_in_stages(stages_rem))

    # Show stages on subplots
    _, ax = plt.subplots(2, 3, figsize=(12, 7))
    ax = ax.flatten()

    for idx, (stage, img) in enumerate(zip(stages_rem, imgs_crop)):
        ax[idx].imshow(img, cmap=plt.get_cmap('gray'))
        ax[idx].set_title("Minute: {}, blobs: {}".format(idx, len(stage)))
        for blob in stage:
            y, x, r = blob
            c = plt.Circle((x, y), r, color='r', linewidth=0.75, fill=False)
            ax[idx].add_patch(c)
    ax[-1].set_axis_off()
    plt.tight_layout()

    # Find all blobs for every stage of cooling
    stages_all = find_blob_series(imgs_prep, only_remaining=False)

    # Show stages on subplots
    _, ax = plt.subplots(2, 3, figsize=(12, 7))
    ax = ax.flatten()

    for idx, (stage, img) in enumerate(zip(stages_all, imgs_crop)):
        ax[idx].imshow(img, cmap=plt.get_cmap('gray'))
        ax[idx].set_title("Minute: {}, blobs: {}".format(idx, len(stage)))
        for blob in stage:
            y, x, r = blob
            c = plt.Circle((x, y), r, color='r', linewidth=0.75, fill=False)
            ax[idx].add_patch(c)
    ax[-1].set_axis_off()
    plt.tight_layout()

    # Show two methods combined to compare
    _, ax = plt.subplots(2, 3, figsize=(10, 7))
    ax = ax.flatten()

    # Show stages on subplots
    loop_set = enumerate(zip(stages_rem, stages_all, imgs_crop))
    for idx, (stage_rem, stage_all, img) in loop_set:
        ax[idx].imshow(img, cmap=plt.get_cmap('gray'))
        ax[idx].set_title("Minute: {}, all blobs: {}, rem blobs: {}".format(
            idx, len(stage_all), len(stage_rem)))
        for blob_all in stage_all:
            y, x, r = blob_all
            c = plt.Circle((x, y), r, color='b', linewidth=0.75, fill=False)
            ax[idx].add_patch(c)
        for blob_rem in stage_rem:
            y, x, r = blob_rem
            c = plt.Circle((x, y), r, color='r', linewidth=0.75, fill=False)
            ax[idx].add_patch(c)
    ax[-1].set_axis_off()
    plt.tight_layout()

    plt.show()