Generating histogram of a gradient image: histogram bar shows a white blank space within a histogram bar
Show older comments
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?
Accepted Answer
More Answers (2)
Sat m
on 3 Mar 2013
17 Comments
Image Analyst
on 3 Mar 2013
Edited: Image Analyst
on 3 Mar 2013
You should have made this a comment, since it's not an answer to your original question. See my demo in my answer above.
Sat m
on 3 Mar 2013
Sat m
on 3 Mar 2013
Image Analyst
on 3 Mar 2013
If you're going to want me to run custom code that does not use a standard demo image, then you should upload your violet.bmp image and let me know where it is.
Sat m
on 3 Mar 2013
Image Analyst
on 3 Mar 2013
Change these lines to this:
[pixelCounts, channels] = hist(sobelImage(:), 50); % hist, not imhist
bar(channels, pixelCounts);
% xlim([0 255]); % Comment out.
Sat m
on 3 Mar 2013
Sat m
on 3 Mar 2013
Image Analyst
on 3 Mar 2013
You didn't change the code like I said. See where I commented out xlim()? Plus, your last subplot is not going to apply to anything since nothing comes after it.
Sat m
on 3 Mar 2013
Image Analyst
on 3 Mar 2013
You need to put the subplot() before the call to bar().
Sat m
on 4 Mar 2013
Sat m
on 4 Mar 2013
Sat m
on 4 Mar 2013
Image Analyst
on 4 Mar 2013
Well what frame do you want them in? In a 2 by 2 array, you can put them into 1-4.
subplot(2,2,1); % Third arg can be 1 - 4. 1-2 is first row, 3-4 is second row.
If you want more, do a 2 by 3 array and you can have up to 6 simultaneously:
subplot(2,3,1); % Third arg can be 1 - 6. 1-3 is first row, 4-6 is second row.
Image Analyst
on 4 Mar 2013
Then call figure() instead of subplot().
Yahye abukar
on 11 May 2016
0 votes
hellow sir i run your code it works fine, but i need to change this code into Prewitt's and Roberts Operators, how i can change this code? thanks
1 Comment
Image Analyst
on 12 May 2016
Yahye, simply use imgradient() - those methods are options for this function built-in to the Image Processing Toolbox.
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!