imhist() returns two arguments. If you have one then it's just the counts:
so hist_xray2 is the counts (bin heights). Now, when you do this:
cdf_input = cumsum(imhist(hist_xray2))/numel(hist_xray2);
you're passing in the counts into imhist(). So essentially you're taking the histogram of the counts, not an image, which makes little sense. Rethink your algorithm.