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: 

2D matrix merge by skipping elements

Solved!
Go to solution

Dear all,

 

I'm trying to merge 4 different 2D matrix into one matrix by skipping elements but unfortunately i have not been able to find skipping mechanism of elements to merge these matrix. Basic example for 2x2 matrix as seen below but real application will be 1824x940 or 1928x1280 and etc. Is there anyone who has an idea?

 

Hawk_se_0-1614967011616.png

 

0 Kudos
Message 1 of 11
(2,977 Views)
Solution
Accepted by topic author Hawk_se

Hi Hawk,

 


@Hawk_se wrote:

I'm trying to merge 4 different 2D matrix into one matrix by skipping elements but unfortunately i have not been able to find skipping mechanism of elements to merge these matrix. Basic example for 2x2 matrix as seen below but real application will be 1824x940 or 1928x1280 and etc. Is there anyone who has an idea?


Some notes:

  • Don't call them "matrix". These are simple 2D arrays!
  • Use BuildArray and TransposeArray to combine your 4 smaller arrays into a big one… (After a second look on your expected result you might use other array functions as well.)

Suggestion:

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 11
(2,953 Views)
Solution
Accepted by topic author Hawk_se

If you attach your example, I can probably make a solution within minutes!

 

Make sure to use unique element. Currently, each 2D input array has identical elements and there are several possibilities to get the desired output.  For example the 1111 at position (0,0) of array 1 could end up at (0,0), (0,2), (2,0) or (2,2) and we cannot tell what's correct without making simplifying assumptions.

 

It is also a bad idea to give an example with square arrays if the real data is not square. Keep the assumptions as small as possible.

0 Kudos
Message 3 of 11
(2,947 Views)
Solution
Accepted by topic author Hawk_se

@altenbach wrote:

If you attach your example, I can probably make a solution within minutes!.


Looks like I got exactly the same idea as Gerd (assuming the simplest interpretation of the ambiguous problem, see above).

 

Another assumption are that all input arrays are the same size. If that cannot be guaranteed, you need to add tests and error handling to avoid unexpected results.

 

altenbach_0-1614970677212.png

 

 

 

There are probably may equally (or even more!) efficient alternatives

0 Kudos
Message 4 of 11
(2,938 Views)

Main application is based on gray scale image which includes Bayer pattern. That's why i need to create random numbers for 4 different colour filter to convert to gray scale 16 bits raw image. 

0 Kudos
Message 5 of 11
(2,932 Views)

You may consider each 2D arrays as filter and they will be merged into one bigger size of mosaic as seen below. My aim is creating these four (4) 2D arrays by generating random number than merge into one big 2D array by skipping elements in order to create grayscale image.

 

Hawk_se_0-1614971671211.png

 

0 Kudos
Message 6 of 11
(2,927 Views)
Solution
Accepted by topic author Hawk_se

Hi Hawk,

 

as I wrote before: don't call those 2D arrays - and don't use matrix functions when there is a huge palette of array functions…

 

Still the same suggestion:

Edit: Christian is right, there's much room for code improvements…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 11
(2,922 Views)

@Hawk_se wrote:

 My aim is creating these four (4) 2D arrays by generating random number than merge into one big 2D array by skipping elements in order to create grayscale image.


This is the first time you mention a random number. How does that fit into the problem? (Does each input array have different random numbers which is the same for all elements? Is each element random? etc.?)

Since the green has twice the area, are you somehow accounting for that to get true grey?

0 Kudos
Message 8 of 11
(2,919 Views)

What is difference between random number or exact character for an element? The main problem is placing into correct position.

0 Kudos
Message 9 of 11
(2,917 Views)

@Hawk_se wrote:

Main application is based on gray scale image which includes Bayer pattern. That's why i need to create random numbers for 4 different colour filter to convert to gray scale 16 bits raw image. 


Why is there so much duplicate code!!!

What are defaults for row&column inputs (currently 0!) and how do the later indices depend on them?

0 Kudos
Message 10 of 11
(2,916 Views)