how to sort histogram generated count and corresponding gray value.. pls help
6 次查看(过去 30 天)
显示 更早的评论
m=imread('ll.bmp');
[count,gray]=imhist(m);
the answer is:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/150253/image.png)
i want to sort the count and corresponding gray value..
and delete the zero count values answer like this..
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/150255/image.png)
0 个评论
采纳的回答
ARJUN K P
2015-5-20
编辑:ARJUN K P
2015-5-20
1 个评论
Image Analyst
2015-5-20
It does the same thing that I did but combined the counts and gray level arrays into a single 2D array (which we didn't know you wanted to do).
更多回答(2 个)
Image Analyst
2015-5-18
Don't use gray as a variable name - it's the name of a built in function that creates a colormap, and you just blew it away.
I don't know why you need to, but to get rid of array elements with zero counts
[count, grayLevels]=imhist(m);
rowsToDelete = count == 0;
count(rowsToDelete) = [];
grayLevels(rowsToDelete) = [];
5 个评论
Image Analyst
2015-5-18
To sort in reverse order, simply use fliplr()
count = fliplr(count)
grayLevels = fliplr(grayLevels);
Image Analyst
2015-5-19
% Sort count in descending order.
[sortedCounts, sortIndexes] = sort(count, 'descend');
% Sort grayLevels the same way.
grayLevels = grayLevels(sortIndexes);
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!