Original Post
Sorry if this isn't the correct forum to put this in but I didn't think it really fit any where else (correct me if I'm wrong - maybe it belongs in the maths forum?) I'm currently programming some image processing software using directx (however it has been abstracted to the point where I do not need to deal with this directly anymore so this is *not* a question about directx). I am creating a histogram based on the image (for your information this is a greyscale image) so the histogram I am creating is comprised of an array of 255 values (integers). I process the image and store a 'sum' of the number of pixels of a certain intensity in the corresponding value of the array (so I end up with 255 values like -> histogramArray[60] = 30, histogramArray[180] = 1286, etc.) I next want to display these values in a histogram. I have therefore created a region next to the image to display this (a white 255x255 square [it is actually slightly bigger than this for a border but that's beside the point]). Next I want to draw a 'column' of pixels based on the values in the histogramArray[] for each of the pixels along the 255 squares' x-axis', i.e. at the bottom left pixel of the square (0,255) I draw a column corresponding in height to the number in histogramArray[0], then at the pixel 'one-over' from this (1,255) I draw a column corresponding in height to the number in histogramArray[1], and so on until the end of the array/white square. The problem I am having is with the scaling of this graph. My height is 'fixed' at 255 (my width is also fixed at this value but this is intentional - i.e. one x-coordinate for each intensity level and I can easily double this up if I want to). Well the height is not *actually* fixed but it *will* be fixed at a *certain* value. So therefore, because the values in histogramArray[] are not guaranteed to below 255 or any other fixed value (so I can use one pixel per value), I need to scale all the values down so that they will all appear relatively on the graph (and the maximum value in the array will be at or just below 255 - *not* above). How do I mathematically perform this scaling? For a certain test picture I am using I have created the histogram using a spreadsheet program and I worked out (through trial and error) what the best value for scaling like this (where the max value from the array is at or just below the max) was (it was 17 for this test picture if you really want to know). What is the best way for finding this value or is there another way to perform this scaling which I have completely missed?? Thanks in advance for any help anyone can give. -Goose