Sorting the connected component

4 ビュー (過去 30 日間)
Tran Tuan Anh
Tran Tuan Anh 2014 年 6 月 16 日
コメント済み: Zikobrelli 2014 年 6 月 16 日
I have a question in sort of connected component. I have a binary image ( onlye 0 and 1) I run the function from matlab: f=
1 0 0 1 0 0 0 1 0 0
1 1 0 1 1 1 0 0 1 0
0 0 0 0 0 0 0 1 1 1
1 0 0 0 1 0 1 0 1 1
1 1 0 0 0 0 0 1 1 1
0 0 0 1 0 0 1 0 0 0
0 0 0 1 0 1 1 0 1 1
1 1 0 0 1 0 0 0 1 0
1 1 0 1 1 1 0 1 0 0
1 1 0 0 1 0 0 0 1 0
[L num]=bwlabel(f);
suppose that they give me the ma trix:
1 0 0 4 0 0 0 5 0 0
1 1 0 4 4 4 0 0 5 0
0 0 0 0 0 0 0 5 5 5
2 0 0 0 6 0 5 0 5 5
2 2 0 0 0 0 0 5 5 5
0 0 0 5 0 0 5 0 0 0
0 0 0 5 0 5 5 0 7 7
3 3 0 0 5 0 0 0 7 0
3 3 0 5 5 5 0 7 0 0
3 3 0 0 5 0 0 0 7 0
But you can see in this resul, the order of matrix is follow the column. Now I want to change this in to the oder rows, that mean number 4 is 2 , number 5 is 3... so on. The oder is left-> right and top -> down. How can I do that ( the oder of reading )??
Thank you so much
  1 件のコメント
Zikobrelli
Zikobrelli 2014 年 6 月 16 日
look at the functions flipud and fliplr.
L1=flipud(fliplr(L))

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

回答 (1 件)

Jos (10584)
Jos (10584) 2014 年 6 月 16 日
Use transpose
[L, num] = bwlabel(transpose(f))
L = transpose(L)
% or use the .' notation to transpose
  2 件のコメント
Tran Tuan Anh
Tran Tuan Anh 2014 年 6 月 16 日
I'm sorry It doesn't solve my problem, because if I use this way with the image:
The firt - second - third connected component is:F -S -l like this figure:
It's wrong, because I want the order of 1-2-3-... is H - a - w-a -(point of I) - (point of I) - dash-i -i -s...
Sean de Wolski
Sean de Wolski 2014 年 6 月 16 日
編集済み: Sean de Wolski 2014 年 6 月 16 日
That's because the top of the S, L and F is higher than the lowercase letters.
You could sort the centroids of the connected components ( bwconncomp ) after calling regionprops and then reorder the output before calling labelmatrix.

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

Community Treasure Hunt

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

Start Hunting!

Translated by