03-05-2021 12:00 PM
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?
Solved! Go to Solution.
03-05-2021 12:22 PM - edited 03-05-2021 12:36 PM
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:
Suggestion:
03-05-2021 12:33 PM - edited 03-05-2021 12:39 PM
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.
03-05-2021 12:53 PM - edited 03-05-2021 12:58 PM
@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.
There are probably may equally (or even more!) efficient alternatives
03-05-2021 01:06 PM
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.
03-05-2021 01:16 PM
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.
03-05-2021 01:18 PM - edited 03-05-2021 01:31 PM
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…
03-05-2021 01:22 PM
@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?
03-05-2021 01:24 PM
What is difference between random number or exact character for an element? The main problem is placing into correct position.
03-05-2021 01:25 PM - edited 03-05-2021 01:29 PM
@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?