how to sort histogram generated count and corresponding gray value.. pls help

m=imread('ll.bmp');
[count,gray]=imhist(m);
the answer is:
i want to sort the count and corresponding gray value..
and delete the zero count values answer like this..

 採用された回答

ARJUN K P
ARJUN K P 2015 年 5 月 20 日
編集済み: ARJUN K P 2015 年 5 月 20 日
i got answer from :
https://www.facebook.com/thematrixcoded
the code is :
m=imread('ll.bmp');
>> [c,g]=imhist(m);
>> K=[c,g];
>> Ks=sortrows(K);
Ki=Ks(end:-1:1,:);
Ki(Ki(:,1)==0,:)=[];
>> Ki
Thanku all for supporting

1 件のコメント

Image Analyst
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
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 件のコメント

ARJUN K P
ARJUN K P 2015 年 5 月 18 日
dear sir,
how to sort both count and corresponding grayLevels values
Image Analyst
Image Analyst 2015 年 5 月 18 日
They are already both sorted in terms of increasing gray level. There is a sort() command to use if you want some different kind of sorting, but you should probably take the sort order and apply it to both so that both arrays are always sorted in the same order.
ARJUN K P
ARJUN K P 2015 年 5 月 18 日
編集済み: ARJUN K P 2015 年 5 月 18 日
sir, already sorted in gray value basis. but i want to sort the count in decreasing (descending) order of sorting.. sir its possible?
To sort in reverse order, simply use fliplr()
count = fliplr(count)
grayLevels = fliplr(grayLevels);
% Sort count in descending order.
[sortedCounts, sortIndexes] = sort(count, 'descend');
% Sort grayLevels the same way.
grayLevels = grayLevels(sortIndexes);

サインインしてコメントする。

ARJUN K P
ARJUN K P 2015 年 5 月 19 日

0 投票

sir you mistaken, i want sort the count in decreasing order...
eg:
before sorting
after sorting
i want ans like

2 件のコメント

Walter Roberson
Walter Roberson 2015 年 5 月 19 日
flipud()
ARJUN K P
ARJUN K P 2015 年 5 月 19 日
its not i want.. i want to sort the count in decreasing order and corresponding gray value.. that i show in above figure...

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeImages についてさらに検索

質問済み:

2015 年 5 月 18 日

コメント済み:

2015 年 5 月 20 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by