Note that there are some explanatory texts on larger screens.

plurals
  1. POMerging 2 Images Using 2D Arrays as Pixels
    text
    copied!<p>I am trying to merge two B&amp;W images based on the following parameters. </p> <p>The new created array use the largest of the two image's width and height as it's own. The int at a specific point in the array contains a number which represents the gray scale amount. The new 2D array will merge the two images based on the following conditions.</p> <ul> <li>If the position exists in both arrays, the value in the results array is the average of the values in array a and b.</li> <li>if the position exists only in array a, the value in the results array is the value in array a</li> <li>if the position exists only in array b, the value in the results array is value in array b</li> <li>if the position is in neither array assign a value of 127 at that position in the results array.</li> </ul> <p>Here is my code. It will not run as it returns an <code>arrayIndexOutOfBounds: 167</code> for some reason. I'd appreciate if someone could look it over.</p> <pre><code>public static int[][] merge(int[][] a, int[][] b) { int biggerx = 0; int biggery = 0; if (a[0].length &gt; b[0].length) { biggery = a[0].length; } else { biggery = b[0].length; } if (a.length &gt; b.length) { biggerx = a.length; } else { biggerx = b.length; } int[][] merged = new int[biggerx][biggery]; for (int x = 0; x &lt; merged.length; x++) { for (int y = 0; y &lt; merged[x].length; y++) { if (x &lt;= a.length &amp;&amp; y &lt;= a[x].length &amp;&amp; x &gt; b.length &amp;&amp; y &gt; b[x].length) { merged[x][y] = a[x][y]; } else if (x &lt;= b.length &amp;&amp; y &lt;= b[x].length &amp;&amp; x &gt; a.length &amp;&amp; y &gt; a[x].length) { merged[x][y] = b[x][y]; } else if (x &lt;= b.length &amp;&amp; y &lt;= b[x].length &amp;&amp; x &lt;= a.length &amp;&amp; y &lt;= a[x].length) { merged[x][y] = ((a[x][y] + b[x][y]) /2); } else { merged[x][y] = 127; } } } return merged; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload