04-16-2012 01:30 PM
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
04-16-2012 01:40 PM
@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
04-16-2012 01:51 PM
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
04-16-2012 01:51 PM
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.
04-16-2012 02:04 PM - edited 04-16-2012 02:05 PM
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.
04-16-2012 02:04 PM
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
04-16-2012 02:09 PM
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.
04-16-2012 02:11 PM
thanks for your answer ben, but could you explain it in another way because i don't really unerstand it very well
04-16-2012 02:13 PM
but thats the part wich doesn't work, i don't know how to change a whole group by -1
04-16-2012 02:17 PM - edited 04-16-2012 02:17 PM
@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.