MATLAB: Generating histogram of a gradient image: histogram bar shows a white blank space within a histogram bar

blank spacegradient maphistogramImage Processing Toolboxthreshold

I have generated a sobel gradient map of an image and now i have to generate the histogram of that gradient map. i did this
[rows, columns, numberOfColorBands] = size(sobelImage);
[pixelCounts, channels] = imhist(sobelImage, 256);
bar(channels, pixelCounts);
xlim([0 255]);
drawnow();
The sobel image is coming good, there is no error. but when i generate the histogram, i can only see a the color scale and a white blank space. can you please tell me how to work through this? and i am asked to only keep certain percentage of pixels from the histogram (e.g. 5% of the highest gradient values) as edge pixels (edgels) and then to use the percentage to find a threshold for the gradient magnitudes. can you please tell me how to solve this?

Best Answer

Is your sobel image the true sobel edge filtered image, or is it the thresholded, skeletonized image returned by edge()? If it's the latter, well, that has only two values. Is sobelImage uint8 or double? You can use cumsum() to find the top 5% of the pixels
cdf = cumsum(pixelCounts) / sum(pixelCounts);
index95 = find(cdf>= 0.95, 1, 'first');
gl95 = channels(index95);