LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Taking every other index from a 2D array and creating a new 2D array

So I am dealing with an image (jpg), I converted that image into a 2D array. I would like to be able to take every other index of that array and store it in a new 2D array. I've tried to look at many examples but many focus on 1D array. This is what I did, not getting anything when I try to run it. I'm pretty new in labview so much help would be appreciated.double for loop iteration.png

0 Kudos
Message 1 of 7
(3,158 Views)

 

A lot of code makes no sense, for example why would you reshape to a 2D array with 1 row. If you want to keep every other row, you need to keep it a 2D array. Now just autoindex on a single FOR loop and conditionally index every odd or even row.

0 Kudos
Message 2 of 7
(3,134 Views)

Here;s one possibility to take all odd indices (odd rows, odd columns, i.e. 4x fewer elements).

 

altenbach_0-1589604382639.png

 

0 Kudos
Message 3 of 7
(3,120 Views)

Just wanted to clarify, like this? I've attached the updated VI too, apologies for the beginning.

 

single for loop iteration.png

 

 

0 Kudos
Message 4 of 7
(3,117 Views)

So that constant 1 on the outside determines whether it's every odd element or even element? So, I could put a 2 there to get every even element? As long as the value doesn't equal 0 then to decimate that index and insert it to the new array? Just want to make sure I understand.

0 Kudos
Message 5 of 7
(3,109 Views)

@TheNameIsBailey wrote:

So that constant 1 on the outside determines whether it's every odd element or even element? So, I could put a 2 there to get every even element? As long as the value doesn't equal 0 then to decimate that index and insert it to the new array? Just want to make sure I understand.


 

No, its always a 1. Basically we are masking off the lowest bit, so the result is zero or one.  If the result is zero, we have an even number and if it is not zero, we have an odd number.

 

Of course you can stick to your Q&R, it's just more computational effort but is more scalable if you e.g. later need code to take every third row.

0 Kudos
Message 6 of 7
(3,087 Views)

oh so to make it get every even we just need to change the command to "=0" instead?

0 Kudos
Message 7 of 7
(3,079 Views)