04-13-2020 05:52 PM
Convert each cell to a cluster that includes a boolean
04-14-2020 07:37 AM
04-14-2020 08:07 AM
Katie,
You may have noticed I reduced your question to finding "islands" on a binary map (I used Booleans randomly distributed on a 2-D grid). Others have made the same suggestion, and Wiebe pointed you to some algorithms that can do this (so you don't need to "reinvent the wheel", you just need to "recode the Wheel using LabVIEW", not necessarily any easier ...).
Before reading about algorithms, however, I would still advise that you create and run some "experiments" with Binary Maps just to get a sense of how things work, and how you might go about creating your own algorithm. You'll definitely get LabVIEW experience in the process.
Bob Schor
04-14-2020 08:35 AM
I'm sure I've done the labeling algorithm myself in LabVIEW.
Must have been 15 years ago... It will be nothing short of a miracle if I can find it.
04-15-2020 06:44 AM
Thank you everyone for your help! I agree that connected-component labeling seems like a great path to go down. I have started making some of my own binary "islands", and will now start trying to create the algorithm. One of my main questions however, is since I have the code in two nested for loops (to iterate through each pixel) I am having trouble figuring out how to get any information out (for example, the location of the current pixel) to add it to a new array. I understand using a second array full of booleans to decipher whether or not that pixel has been iterated through or not, but I am getting stuck then trying to add that pixel location to another array (to form the islands).
I am going to work on this code a lot today and see if I get anywhere. Thank you everyone!
04-15-2020 06:57 AM
I'd say, use a shift register on both loops, and array indexing to get\set the correct element. Initialize the array (put it in the left shift register) with the correct size.
But this is just the default answer for questions like this. If you post a VI (and optionally an image of it) we can give a more to the point answer.
04-15-2020 11:00 AM
wiebe@CARYA wrote:
I'm sure I've done the labeling algorithm myself in LabVIEW.
Must have been 15 years ago... It will be nothing short of a miracle if I can find it.
here we go
https://forums.ni.com/t5/LabVIEW/Floodfill-Algorithm/m-p/438947#M214627
04-15-2020 11:17 AM
@alexderjuengere wrote:
wiebe@CARYA wrote:
I'm sure I've done the labeling algorithm myself in LabVIEW.
Must have been 15 years ago... It will be nothing short of a miracle if I can find it.
here we go
https://forums.ni.com/t5/LabVIEW/Floodfill-Algorithm/m-p/438947#M214627
That is hilarious!
04-16-2020 11:42 AM
Wow thank you so much Wiebe and Alex!
I've been modifying the floodfill VI for a little while now to get it to work with my input data, and there are some cases where I am having trouble. What I have done is I made the input and output data a 2d array of binary 1s and 0s. If the vi detects a 1, it will run the algorithm, and change any 1s in an island to a 2 (just to differentiate each island). Ideally, I would want the next island to change from 1s to 3s, and so on. If my input data has multiple islands, or whatever you may want to call them, it seems as if the VI only completes the flood fill on the last island it detects. I watched the VI run for a while with highlight execution, and I saw it work on the other islands, but once it did not detect any more elements in that island, the values went back to their initial state.
I'm just confused on why values of island 1 go back to 1 after island 2 is detected. I included the vi because it will probably be easier to understand my issue by looking at it. If you run the vi, and look at the output array, you will notice it only changes the very last island it detects (which consists of 2 elements) while all the other islands have a value of 1 still. Thank you!
04-17-2020 02:24 AM
There are a few obvious problems. Some might be mine, some yours.
The locals are not needed, and a bug. The locals can be read before they are written, resulting in usages of the previous indices. Just use the wires!
The output array is in the nested for loops. So it will start with the original data each iteration of the for loops. So, old results are gone. You probably need to use shift registers on the two for loops as well.
The inner while loop is a recursive algorithm. It adds neighboring pixels to the list, and adds neighboring pixels to them (etc.). If I had to do this now, I'd use a recursive VI, not a loop.
The recursion is inefficient if you're going over each pixel anyway. For a flood fill algorithm it's OK, as this might cover only a fraction of the total amount of pixels. But as you're going over all pixels anyway, many pixels will be visited several times, wasting CPU time.
Attached is a flood fill, hopefully doing the same as yours, but cleaned up and some problems fixed. Untested 😁.
I'll have a go at the wiki labeling algorithm.