<html>
    <head>
      <base href="http://fiji.sc/bugzilla/" />
    </head>
    <body><span class="vcard"><a class="email" href="mailto:ctrueden@wisc.edu" title="Curtis Rueden <ctrueden@wisc.edu>"> <span class="fn">Curtis Rueden</span></a>
</span> changed
              <a class="bz_bug_link 
          bz_status_CONFIRMED "
   title="CONFIRMED - Process-Math-Macro..."
   href="http://fiji.sc/bugzilla/show_bug.cgi?id=1169">bug 1169</a>
          <br>
             <table border="1" cellspacing="0" cellpadding="8">
          <tr>
            <th>What</th>
            <th>Removed</th>
            <th>Added</th>
          </tr>

         <tr>
           <td style="text-align:right;">Status</td>
           <td>NEW
           </td>
           <td>CONFIRMED
           </td>
         </tr>

         <tr>
           <td style="text-align:right;">CC</td>
           <td>
                
           </td>
           <td>ctrueden@wisc.edu
           </td>
         </tr></table>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_CONFIRMED "
   title="CONFIRMED - Process-Math-Macro..."
   href="http://fiji.sc/bugzilla/show_bug.cgi?id=1169#c1">Comment # 1</a>
              on <a class="bz_bug_link 
          bz_status_CONFIRMED "
   title="CONFIRMED - Process-Math-Macro..."
   href="http://fiji.sc/bugzilla/show_bug.cgi?id=1169">bug 1169</a>
              from <span class="vcard"><a class="email" href="mailto:ctrueden@wisc.edu" title="Curtis Rueden <ctrueden@wisc.edu>"> <span class="fn">Curtis Rueden</span></a>
</span></b>
        <pre>What happens is: the Process > Math > Macro... command iterates over every
pixel, replacing each value in-place as it goes. By referencing previously
processed pixels via getPixel(x-1, y-1) you are subtracting your new pixel
values instead of your original ones.

Interesting that it works in 8-bit, but not 16-bit. Looking at the source, this
is because there is special case logic for 8-bit and RGB images [1] which
copies the pixel buffer before executing in the case where the getPixel
function is used [2, 3]. However, no such thing is done for 16-bit [4].

As a workaround, you can instead write:

  v=getPixel(x+1, y+1)-getPixel(x, y);

Which avoids the issue.

I agree that this is a bug, in that the behavior between 8-bit and 16-bit is
inconsistent.

[1]
<a href="https://github.com/imagej/ImageJA/blob/v1.50b/src/main/java/ij/plugin/filter/ImageMath.java#L254-L335">https://github.com/imagej/ImageJA/blob/v1.50b/src/main/java/ij/plugin/filter/ImageMath.java#L254-L335</a>
[2]
<a href="https://github.com/imagej/ImageJA/blob/v1.50b/src/main/java/ij/plugin/filter/ImageMath.java#L277">https://github.com/imagej/ImageJA/blob/v1.50b/src/main/java/ij/plugin/filter/ImageMath.java#L277</a>
[3]
<a href="https://github.com/imagej/ImageJA/blob/v1.50b/src/main/java/ij/plugin/filter/ImageMath.java#L319">https://github.com/imagej/ImageJA/blob/v1.50b/src/main/java/ij/plugin/filter/ImageMath.java#L319</a>
[4]
<a href="https://github.com/imagej/ImageJA/blob/v1.50b/src/main/java/ij/plugin/filter/ImageMath.java#L321-L334">https://github.com/imagej/ImageJA/blob/v1.50b/src/main/java/ij/plugin/filter/ImageMath.java#L321-L334</a></pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>