LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

remove zero's in a certain area

no the problem is that i have several areas where 1's are touching eachother, and these areas are seperated with zero's

i want to make a program who counts this areas of 1's by replacing step for step one of these areas with an area of zero's so i could count how many areas there were

 

is this a more clare specification of the problem

 

for instance

 

00000000000000000000000000000000

00000000000001000000000000000000

00011110000111111000000000000000

0111111000000111000000000000000

000000000000000000000000000000

0 Kudos
Message 11 of 25
(821 Views)

@ggqshqs wrote:

no the problem is that i have several areas where 1's are touching eachother, and these areas are seperated with zero's

i want to make a program who counts this areas of 1's by replacing step for step one of these areas with an area of zero's so i could count how many areas there were

 

is this a more clare specification of the problem

 

for instance

 

00000000000000000000000000000000

00000000000001000000000000000000

00011110000111111000000000000000

0111111000000111000000000000000

000000000000000000000000000000


 

Not enough for me.

 

I'm guessing you want to come up with the answer "2" for that data set.

 

If so you will need code to start checking at (0,0) and then once a "1" is found check the value values that floow in that row until you find a zero.

 

For evey additional "1" found you also want to check down still applying the same rule.

 

Soo you are trying to do what Paint does when it does a fill.

 

I'm done since I still don't know if that is what you want.

 

Ben

 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 12 of 25
(807 Views)

I think that the real problem with my program is that the recursive part doesn't work and i don't know whats the problem

0 Kudos
Message 13 of 25
(800 Views)

As Ben pointed out, you really need a particular alogorthim for counting groups of one's that is far beyond your original request of "removing 1's in an area".

 

I don't know if you are going to be able to get much help.  Perhaps there are some functions in the IMAQ vision palette that can do what you want.  But you would need the help of someone familiar with that and has some similar activities before.

 

Otherwise, start googling and search for algorithms that can help you identify disctinctive clusters of 1's.

0 Kudos
Message 14 of 25
(799 Views)

You still really haven'd define "adjacent".

 

Are two elements that only touch at a corner adjacent?

Do they need to share at least one side to be adjacent?

How should a scenario be treated where a group of ones has holes? what if there is another group inside the hole?

 

For example:

 

Is this one group or three groups?

 

00000000

00100000

00010000

00100000

 

How may groups are here?

 

0000000000000000000000

0000000011111100000000

0000001111111111100000

0000011000000001111000

0000011001110000011000

0000001100110001111000

0000001110000111000000

0000000111111100000000

 

 In any case, there is no recursion needed. Use one flat loop and iterate over adjacent positions until a border is found.

0 Kudos
Message 15 of 25
(793 Views)

For get the recursion approach in LV.

 

If the recursive routine required a new instance for every pixel found true, a completely black image will crash LV (unless they have changed recursion).

 

Instead iterate.

 

Here is an outline;

 

Crate an empty array of cluster with two elements to store the X and Y index.

 

Wire that array to a shift register on the edge of a pair of nested For Loop and let LV index through your image data array.

 

In the inner Check if the value is 1. If so check to see if it in the array of clusters (indicating you found this one already). If it is not in your list you found a new region, add the XY value to your list in the SR and increment your "object count" (yet another SR).

 

Using the index where you found the "1" and check the values at the eight adjacent locations and for each one that is "1" add it to the list of found but don't increment the count since you are still examining the same blob.

 

I'll let you do the rest but I suggest you just track the number of blobs and a list of locations where the the value was "1" and just LOOK at the data array.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 16 of 25
(791 Views)

FInd the first array max. now iterate over adjacent elements and replace them with -1 until you handled the entire group. Now find he next array max, and repeat the same, replacing elements with -2. Continue until the array max is 0, at which point you negate the "array min" to get the number of groups.

0 Kudos
Message 17 of 25
(786 Views)

thanks for your answer ben, but could you explain it in another way because i don't really unerstand it very well

0 Kudos
Message 18 of 25
(785 Views)

but thats the part wich doesn't work, i don't know how to change a whole group by -1

 

0 Kudos
Message 19 of 25
(782 Views)

@ggqshqs wrote:

but thats the part wich doesn't work, i don't know how to change a whole group by -1


One element at a time as you inspect it, and using replace array subset. Keep the 2D array in a shift register.

0 Kudos
Message 20 of 25
(776 Views)