def main():
    """ The main funtion that parses input arguments, calls the approrpiate
     interpolation method and writes the output image"""

    #Parse input arguments
    from argparse import ArgumentParser

    parser = ArgumentParser()

    parser.add_argument("-i",
                        "--image",
                        dest="image",
                        help="specify the name of the image",
                        metavar="IMAGE")

    args = parser.parse_args()

    #Load image
    if args.image is None:
        print("Please specify the name of image")
        print("use the -h option to see usage information")
        sys.exit(2)
    else:
        image_name = args.image.split(".")[0]
        input_image = cv2.imread(args.image, 0)

    h = input_image.shape
    n = h[0] * h[1]

    bin_img = bi.binary_image()
    hist = bin_img.compute_histogram(input_image)

    threshold = bin_img.find_optimal_threshold(hist, n)
    print("Optimal threshold: ", threshold)

    binary_img = bin_img.binarize(input_image, threshold)
    display_image('w', binary_img)
    outputDir = 'output/cellct/'

    #Saving histogram to output directory
    hist_fig = plt.plot(hist)
    plt.savefig(outputDir + "hist.png")

    output_image_name = outputDir + "binary_image_" + datetime.now().strftime(
        "%m%d-%H%M%S") + ".jpg"
    cv2.imwrite(output_image_name, binary_img)

    #blobcoloring
    cell_count_obj = cc.cell_counting()

    regions, k, i = cell_count_obj.blob_coloring(binary_img)
    [region, hist] = cell_count_obj.compute_statistics(regions, k, i)

    cell_stats_img = cell_count_obj.mark_regions_image(region, hist)
    output_image_name = outputDir + "cell_stats_" + datetime.now().strftime(
        "%m%d-%H%M%S") + ".jpg"
    cv2.imwrite(output_image_name, cell_stats_img)
def main():
    """ The main funtion that parses input arguments, calls the approrpiate
     interpolation method and writes the output image"""

    #Parse input arguments
    from argparse import ArgumentParser

    parser = ArgumentParser()

    parser.add_argument("-i",
                        "--image",
                        dest="image",
                        help="specify the name of the image",
                        metavar="IMAGE")

    args = parser.parse_args()

    #Load image
    if args.image is None:
        print("Please specify the name of image")
        print("use the -h option to see usage information")
        sys.exit(2)
    else:
        image_name = args.image.split(".")[0]
        input_image = cv2.imread(args.image, 0)

    bin_img = bi.binary_image()
    hist = bin_img.compute_histogram(input_image)

    outputDir = 'output/cellct/'
    outputDir_compress = 'output/Compression/'

    #Saving histogram to output directory
    hist_fig = plt.plot(hist)
    plt.savefig(outputDir + "hist.png")

    threshold = bin_img.find_optimal_threshold(hist)
    print("Optimal threshold: ", threshold)

    binary_img = bin_img.binarize(input_image)
    output_image_name = outputDir + "binary_image_" + datetime.now().strftime(
        "%m%d-%H%M%S") + ".jpg"
    cv2.imwrite(output_image_name, binary_img)

    #blobcoloring
    cell_count_obj = cc.cell_counting()

    regions = cell_count_obj.blob_coloring(binary_img)
    stats = cell_count_obj.compute_statistics(regions)

    cell_stats_img = cell_count_obj.mark_regions_image(binary_img, stats)
    output_image_name = outputDir + "cell_stats_" + datetime.now().strftime(
        "%m%d-%H%M%S") + ".jpg"
    cv2.imwrite(output_image_name, cell_stats_img)

    #Compression
    rle_obj = rle.rle()
    rle_code = rle_obj.encode_image(binary_img)
    print("-------------- Runlength Code -------------------")
    print(rle_code)

    [height, width] = binary_img.shape

    decoded_image = rle_obj.decode_image(rle_code, height, width)

    output_image_name = outputDir_compress + "decoded_image_" + datetime.now(
    ).strftime("%m%d-%H%M%S") + ".jpg"
    cv2.imwrite(output_image_name, decoded_image)