예제 #1
0
파일: task_II.py 프로젝트: Darthfett/MIS-P3
def generate_histogram(image, image_id, color_space, hist_spec):
    """
    Given an image, target operational color space, and the histogram spec from task I,
    divide the image into 8x8 image cells, and generate a histogram for each cell,
    according to the specification generated by task I.
    """
    pixels = image.getdata()
    width = image.size[0]

    # Convert to target operational color space
    pixels = [convert_pixel(pixel, "rgb", color_space) for pixel in pixels]

    # Split the image into 8x8 image cells
    image_cells = list(get_image_cells(pixels, width, 8, 8))

    histogram_output = []
    for cell_coord, cell in enumerate(image_cells):
        # Dictionary mapping bin id to number of pixels in the bin
        bin_counter = dict(zip(range(16), [0] * 16))

        for pix_coord, pixel in enumerate(cell):
            # Get bin for pixel
            bin_counter[bin_pixel(pixel, hist_spec)] += 1

            # Output
        for color_instance_id, value in bin_counter.items():
            histogram_output.append((image_id, cell_coord, color_instance_id, value))

    return histogram_output
예제 #2
0
파일: task_IV.py 프로젝트: Darthfett/MIS-P3
def angle_histogram_generator(image, image_id, color_space):
    '''
    given a pil image, the name of that image and a colorspace to work in:
    splits the image into 8x8 cells, generates a histogram for each cell.

    '''
    pixels = image.getdata()
    width = image.size[0]
    #pixels = [convert_pixel(pixel, color_space, "yuv") for pixel in pixels]

    c1,c2,c3 = zip(*pixels)#separate out luminance
    if color_space == "RGB" or "rgb":
        n1 = 'R'
        n2 = 'G'
        n3 = 'B'
    elif color_space == "YUV" or "yuv":
        n1 = 'Y'
        n2 = 'U'
        n3 = 'V'
    else:
        n1 = 'H'
        n2 = 'S'
        n3 = 'V'
    histogram_output = []

    #for c1:
    image_cells = list(get_image_cells(c1, width, 8, 8))
    for cell_coord, cell in enumerate(image_cells):
        color_instance_id_list, value_list = get_hist_angle_bins(cell)
        for i in range (0,16):
            histogram_output.append((image_id, cell_coord, n1, i, value_list[i]))
    #for c2:
    image_cells = list(get_image_cells(c2, width, 8, 8))
    for cell_coord, cell in enumerate(image_cells):
        color_instance_id_list, value_list = get_hist_angle_bins(cell)
        for i in range (0,16):
            histogram_output.append((image_id, cell_coord, n2, i, value_list[i]))
    #for c3:
    image_cells = list(get_image_cells(c3, width, 8, 8))
    for cell_coord, cell in enumerate(image_cells):
        color_instance_id_list, value_list = get_hist_angle_bins(cell)
        for i in range (0,16):
            histogram_output.append((image_id, cell_coord, n3, i, value_list[i]))
    return histogram_output
예제 #3
0
파일: task_VI.py 프로젝트: Darthfett/MIS-P3
def dwt_freq_generator(image, image_id, color_space):
    pixels = list(image.getdata())
    width = image.size[0]

    # Split the image into 8x8 image cells
    image_cells = list(get_image_cells(pixels, width, 8, 8))

    output = []
    for cell_coord, cell in enumerate(image_cells):
        channels = zip(*cell)

        for channel_id, channel in enumerate(channels):
            freq_components = sum([list(x) for x in dwt(list(grouper(width, channel)))], [])

            most_significant = freq_components[:16]
            for freq_bin, value in enumerate(most_significant):
                output.append((image_id, cell_coord, channel_id, freq_bin, value))
    return output