public static AsciiImage getHistogram(AsciiImage img) {
        HashMap<Character,Integer> freqMap = new HashMap<Character, Integer>();

        String oldCharset = img.getCharset();
        String newCharset;
        newCharset = oldCharset;
        for(int i = 0; i<=9; i++) {
            if (oldCharset.indexOf(i + '0') < 0)
                newCharset = i + newCharset;
        }
        if(oldCharset.indexOf('.') < 0)
            newCharset = newCharset + '.';
        if(oldCharset.indexOf('#') < 0)
            newCharset = '#' + newCharset;
        int width = 3+oldCharset.length();
        AsciiImage histo = new AsciiImage(width, 16, newCharset);

        List<Integer> heights = new ArrayList<Integer>();
        int max = 0;
        Character mostFrequent = oldCharset.charAt(0);

        //find the most frequent character
        for(Character c:oldCharset.toCharArray()) {
            int count = img.getPointList(c).size();
            if(count > max) {
                max = count;
                mostFrequent = c;
            }
            freqMap.put(c,count);
        }

        for(Character c:oldCharset.toCharArray()) {
            heights.add(getHeight(freqMap.get(c), freqMap.get(mostFrequent)));
        }

        //build the strings that make up the scale
        List<String> scaleStrings = buildScale(freqMap.get(mostFrequent), img.getHeight()*img.getWidth());
        String image = "";
        //pad the strings to the width of the image and concatenate them to one image
        for (String scaleString : scaleStrings) {
            String s = pad(scaleString, width);
            image += s + "\n";
        }
        Operation o = new LoadOperation(image);
        try {
            //fill the histogram with the scale
            histo = o.execute(histo);
        } catch (OperationException e) {
            e.printStackTrace();
        }
        insertBars(histo, heights);
        insertCharset(histo, oldCharset);
        //flip the histogram, because it is upside down the way we created it now
        return flip(histo);
    }