Urgent help with connected component labeling
2 次查看(过去 30 天)
显示 更早的评论
Hello Experts,
I need some urgent help with matlab code, I have an exam in app. 2 hours and I need to write a function that gets a binary picture (matrix) and returns a matrix with the same size in which each connected componnent is tagged with a different label.
Please be so kind and provide me the code, it's very urgent.
2 个评论
Geoff
2012-5-21
You haven't been posting responses in your last question ever since you emailed me asking for private mentoring. If you have specific problems, whether they be syntactic, logical or conceptual, please describe them, and we may be able to help you. I do wonder how long you've known about this exam, and how much time you set aside to prepare, given that it appears you are having difficulty with this particular subject. Have you implemented a Union Find algorithm yet? Or did you have another method for relating the pixels?
Walter Roberson
2012-5-21
http://www.mathworks.com/matlabcentral/answers/29922-why-your-question-is-not-urgent-or-an-emergency
回答(1 个)
Image Analyst
2012-5-21
And what was wrong with the algorithm that kind Geoff described for you in your duplicate question? Did you want him to post his code so that you could turn his code in as your own for your test?
2 个评论
Geoff
2012-5-21
Hang on a minute.... An exam is designed to test YOUR ability, not ours!
I can point out a logic error right now though... "i" and j" will NEVER be greater than size(img,1) and size(img,2) respectively. You want to test if i > 1 or j > 1 here, but you need to read my answer to your other question again and/or think about exactly what that code does and when it does it.
But your concept is not going to work. All it does is individually labels all pixels that have a neighbour on the left or above. It doesn't actually connect the sets.
What you actually need to do here is implement Union Find and do this:
* if neighbour on left, union thispixel with leftpixel
* if neighbour above, union thispixel with abovepixel
It might be a little late to implement union find... But if you want to cheat, you can probably just google "union find code for matlab". In fact, Google solves about 90% of questions that are asked here.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!