Affinity Preserving Quantization for Hashing: A Vector Quantization Approach to Learning Compact Binary Codes