コード例 #1
0
def three_seven():
    """
    3.7
    Obtain the unnormalized and the normalized histograms of the following 8-bit,
    MxN image.  Give your histogram either in a table or a graph, labeling clearly
    the value and location of each histogram component in terms of M and N.
    Double-check your answer by making sure that the histogram components add to the
    correct value.
    """
    figure_image = np.array([
        [240, 240, 240, 16, 16, 16, 32, 32, 32, 32, 32, 32, 32],
        [240, 240, 240, 16, 16, 16, 228, 32, 32, 32, 32, 32, 255],
        [240, 240, 240, 16, 16, 16, 228, 228, 32, 32, 32, 255, 255],
        [240, 240, 240, 16, 16, 16, 228, 228, 228, 32, 255, 255, 255],
        [240, 240, 240, 16, 16, 16, 228, 228, 228, 0, 255, 255, 255],
        [240, 240, 240, 16, 16, 16, 228, 228, 0, 0, 0, 255, 255],
        [240, 240, 240, 16, 16, 16, 228, 0, 0, 0, 0, 0, 255],
        [240, 240, 240, 16, 16, 16, 0, 0, 0, 0, 0, 0, 0],
        [127, 127, 127, 191, 191, 191, 0, 0, 0, 0, 0, 0, 0],
        [127, 127, 127, 191, 191, 191, 0, 0, 0, 0, 0, 0, 0],
        [127, 127, 127, 191, 191, 191, 0, 0, 0, 0, 0, 0, 0],
    ])

    rows, columns = figure_image.shape

    ImageDisplay.display_image(figure_image)

    histogram = ImageStatistics.calculate_histogram(figure_image)

    # calculate normalized histogram
    counts = 0
    for value in histogram:
        counts += value

    normalized_histogram = histogram / (rows * columns)

    print(histogram)

    plt.hist(figure_image)
    plt.show()

    plt.plot(histogram, label="unnormalized histogram")
    plt.legend()
    plt.show()

    plt.plot(normalized_histogram, label="normalized histogram")
    plt.legend()
    plt.show()
コード例 #2
0
def three_five():
    """
    3.5
    Do the following:
    (a) Purpose a method for extracting the bit planes of an image based on
    converting the value of its pixels to binary.
    (b) Find all the bit planes o the following 4-bit image:
            0  1  8  6
            2  2  1  1
            1  15 14 12
            3  6  9  10
    """
    four_bit_image = np.array([[0, 1, 8, 6], [2, 2, 1, 1], [1, 15, 14, 12],
                               [3, 6, 9, 10]])

    ImageDisplay.display_image(four_bit_image)

    bit_planes = ImageAnalysis.calculate_bit_planes(four_bit_image,
                                                    bits_per_pixel=4)

    ImageDisplay.display_bit_planes(bit_planes * 256)