title: Adaptive Median Filter
body: <p>I am constructing code for adaptive median filter . When i execute it it gives me error at line No 12. Not enough arguments. and on line 28.Unexpected MATLAB Expression.</p>
  
  <pre><code> function f = adpmedian(g, Smax)
  
  
      %ADPMEDIAN Perform adaptive median filtering.
  
      %   F = ADPMEDIAN(G, SMAX) performs adaptive median filtering of
  
      %   image G.  The median filter starts at size 3-by-3 and iterates up   
  
      %   to size SMAX-by-SMAX. SMAX must be an odd integer greater than 1.
  
      % SMAX must be an odd, positive integer greater than 1.
  
        **12&gt;&gt;**if (Smax &lt;= 1) || (Smax/2 == round(Smax/2)) || (Smax ~= round(Smax))
             error('SMAX must be an odd integer &gt; 1.')
          end
          [M, N] = size(g);
          % Initial setup.
          f = g;
          f(:) = 0;
          alreadyProcessed = false(size(g));
          % Begin filtering.
          for k = 3:2:Smax
             zmin = ordfilt2(g, 1, ones(k, k), 'symmetric');
             zmax = ordfilt2(g, k * k, ones(k, k), 'symmetric');
             zmed = medfilt2(g, [k k], 'symmetric');
         `28&gt;&gt;`    processUsingLevelB = (zmed &gt; zmin) &amp; (zmax &gt; zmed) &amp; ...
                 ~alreadyProcessed; 
             zB = (g &gt; zmin) &amp; (zmax &gt; g);
             outputZxy  = processUsingLevelB &amp; zB;
             outputZmed = processUsingLevelB &amp; ~zB;
             f(outputZxy) = g(outputZxy);
             f(outputZmed) = zmed(outputZmed);
             alreadyProcessed = alreadyProcessed | processUsingLevelB;
  
             if all(alreadyProcessed(:))
                break;
             end
  
          end
  
      % Output zmed for any remaining unprocessed pixels. Note that this
      % zmed was computed using a window of size Smax-by-Smax, which is
      % the final value of k in the loop.
      f(~alreadyProcessed) = zmed(~alreadyProcessed);
  </code></pre>