public JSONObject countMetadataColors(JSONObject[] countMetadata, Color[] colors, float[] weights)
        throws TinEyeServiceException
    {
        MultipartEntity postEntity = new MultipartEntity();
        JSONObject responseJSON = null;

        if (weights.length > 0 && colors.length != weights.length)
            throw new TinEyeServiceException("colors and weights lists must have the same number of entries");

        try
        {
            int i = 0;
            for(JSONObject metaData: countMetadata)
            {
                postEntity.addPart("count_metadata[" + i + "]", new StringBody(metaData.toString()));
                i += 1;
            }

            // Store list of colors in hex format, and disgard
            // the alpha component from each color (which by default is white)
            int j = 0;
            for(Color color: colors)
            {
                String hexColor = Integer.toHexString(color.getRGB()).substring(2);
                postEntity.addPart("colors[" + j + "]", new StringBody(hexColor));

                // weights must be the same length as the colors if the weights list is not empty.
                if (weights.length > 0)
                {
                    postEntity.addPart("weights[" + j + "]", new StringBody(Float.toString(weights[j])));
                }

                j += 1;
            }

            responseJSON = postAPIRequest("count_metadata", postEntity);
        }
        catch (Exception e)
        {
            logger.error("'countMetadataColors' failed: " + e.toString());
            throw new TinEyeServiceException("'countMetadataColors' failed", e);
        }
        return responseJSON;
    }