Optimizing visual dictionaries for effective image retrieval