How to fill a gap in a single width image?

1 vue (au cours des 30 derniers jours)
Meshooo
Meshooo le 15 Oct 2013
Modifié(e) : Meshooo le 23 Jan 2014
Dear all, I have an 15X1 logical image for example like this:
0 0 0 1 1 0 0 0 1 1 1 1 0 0 0
As we see, the one's are not connected. I want to make a program that connect the gap between the one's similar the the imfill function in matlab but which can be applied in a single width image. In other words, how to get answer like this 0 0 0 1 1 1 1 1 1 1 1 1 0 0 0
I would appreciate it very much to hear some suggestions.
Meshoo

Réponse acceptée

Walter Roberson
Walter Roberson le 15 Oct 2013
P = find(M, 1, 'first'); %here 1 is number of items to match, not value to match
Q = find(M, 1, 'last');
N = M;
N(P:Q) = 1;
  1 commentaire
Meshooo
Meshooo le 15 Oct 2013
Yes, it works very well. Thank you very much.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Image Segmentation and Analysis dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by