Let's see how to compress an image using vector quantization:
- The full code for this recipe is given in the vector_quantization.py file that has already been provided to you. Let's take a look at how it's built. We'll start by importing the required packages. Create a new Python file, and add the following lines:
import argparse import numpy as np from scipy import misc from sklearn import cluster import matplotlib.pyplot as plt
- Let's create a function to parse the input arguments. We will be able to pass the image and the number of bits per pixel as input arguments:
def build_arg_parser(): parser = argparse.ArgumentParser(description='Compress the input image \ using clustering') parser.add_argument("--input-file", dest="input_file", ...