From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I remove elements from a 2-D array?

Solved!
Go to solution

Hello all!

 

I've asked a similar question in the past, but I'm looking at a slightly different scenario now. I have a 2-d array of 8-bit values that form a video image, but I'm trying to remove a certain number of the highest values in the image. In order to prevent the image from being horribly thrown off, I figured I'd replace those values with NaN. While I thought this would be simple, I've been having issues accessing elements in the middle of a 2-D array. I've attached my code, but I'm afraid it won't be that helpful, it was something of a poor attempt (but it's my most complete).

 

Thank you for your time Smiley Happy,

-Gobble

----------------------------------------------------------------------------------------------------------------------------------------
LabView 8.5.1
0 Kudos
Message 1 of 9
(5,329 Views)

All your subVIs are missing. Can you attach it once more with the 2D array containing typical default data?

 

I am not sure why you are operating on 1D arrays, seems lossy. Also, to create a NaN constant, just create a diagram constant and type "NaN". Voila! No need to divide zero by zero! 😄

 

One possibility if there are only few large values: Keep the 2D array in a shift register and do  "array min/max" on the 2D array use the index(max) to replace the element with a smaller one. Repeat a few times.

 

In the more general case, you could also compare the 2D array with a threshold, create a mask, and multiply the array and mask.

 

 

Message 2 of 9
(5,317 Views)
Solution
Accepted by topic author GobbleDiGhoul

First of all, eight bit values (U8) don't have NaN. Are you using the correct representation?

You might want to replace with zero (for example) instead.

 

Here are two simple ways using DBL arrays, because that's what you actually have. Modify as needed.

Message 3 of 9
(5,310 Views)

Altenbach,

 

Thanks for the tips! I'll try out the NaN thing as soon as I get the chance (I'm at another computer while mine is being used. Such is the life of an intern.) I don't like using 1-D arrays either, but my main issue is that labview isn't accepting 2-D index values in either the "Replace Array Subset" or the "Delete From Array" functions. When I put the array through the min/max function, it returns a 1-D array with 2 values, the index of the max value. Good so far. But when I try and put that into any other function, it doesn't accept it, saying it only works for a long (or similar). I thought it might work if I cut my 2-D array into 1-D arrays and just stitched it back together afterwards, but I was getting weird results (I would need more than rows, for one, but even given that the results were odd). Otherwise, I was going for something very similar to your first suggestion.

 

I'll try to upload a better program when I get the chance, but I've never simulated camera data, so it'll be interesting.

 

Thanks so much again! Smiley Very Happy

-Gobble

----------------------------------------------------------------------------------------------------------------------------------------
LabView 8.5.1
0 Kudos
Message 4 of 9
(5,308 Views)

Oops! I replied before seeing your second response. That looks perfect, thanks! And sorry about my mispeaking, you are correct that the values are not 8-bit. I'm in the habit of explaining it that way to my coworkers, but the value is translated to an integer.

 

I can't wait to implement it! Thanks again!

-Gobble

----------------------------------------------------------------------------------------------------------------------------------------
LabView 8.5.1
0 Kudos
Message 5 of 9
(5,305 Views)

Depending on how big the arrays, are you might want to keep them in shift registers in the case of the stacked loops and do explicit replace operations in the innermost loop. Watch for extra buffer allocations.

 

Even the autoindexing is quite efficient, though, so see how it goes.

Message 6 of 9
(5,300 Views)

 


@GobbleDiGhoul wrote:

I don't like using 1-D arrays either, but my main issue is that labview isn't accepting 2-D index values in either the "Replace Array Subset" or the "Delete From Array" functions. When I put the array through the min/max function, it returns a 1-D array with 2 values, the index of the max value. Good so far. But when I try and put that into any other function, it doesn't accept it, saying it only works for a long (or similar). I thought it might work if I cut my 2-D array into 1-D arrays and just stitched it back together afterwards, but I was getting weird results (I would need more than rows, for one, but even given that the results were odd). 


 

A few more comments to your post:

 

You cannot delete a single element from a 2D graph. You can only delete entire rows or columns (A 2D array cannot have "holes").

"Replace array subset" is the correct function here, and that works fine with 2D indices. Here's a quick example that replaces the 10 largest values of a 2D array with NaN (this is just an illustration, not an endorsement that it should be done exactly as shown ;))

 

A 2D array has HxW elements. You are extracting a single row and a single column and building them back into a Nx2 array. Thus you are probably retaining only a small fraction of all elements, right? (For example if you start out with a 10x10 image, you'll end up with a 10x2 array, losing 80% of the elements).

 

Message 7 of 9
(5,287 Views)

Thank you Altenbach!

 

I ended up going with something very similar to what you've shown in the last post. I've yet to test it out (oh, to have my own work station) but I'm confident it will work. Thank you so much for your time!

 

-Gobble

----------------------------------------------------------------------------------------------------------------------------------------
LabView 8.5.1
0 Kudos
Message 8 of 9
(5,258 Views)


Please I would like to know how I can replace a number elements in an Array with zeros where the indexes of the elements to be replaced are built up in an array form too.

0 Kudos
Message 9 of 9
(5,183 Views)