Extremely fast 2D image convolution with a max filter.


function J = convMax( I, r, nomex )


 Extremely fast 2D image convolution with a max filter.

 For each location computes J(y,x) = max(max(I(y-r:y+r,x-r:x+r))). The
 filtering is constant time per-window, independent of r. First, the
 filtering is separable, which brings the complexity down to O(r) per
 window from O(r*r). To bring the implemention down to constant time
 (independent of r) we use the van Herk/Gil-Werman algorithm. Ignoring
 boundaries, just 3 max operations are need per-window regardless of r.

 The output is exactly equivalent to the following Matlab operations:
  I=padarray(I,[r r],'replicate','both'); [h,w,d]=size(I); J=I;
  for z=1:d, for x=r+1:w-r, for y=r+1:h-r
        J(y,x,z) = max(max(I(y-r:y+r,x-r:x+r,z))); end; end; end
 The computation, however, is an order of magnitude faster than the above.

  J = convMax( I, r, [nomex] )

  I      - [hxwxk] input k channel single image
  r      - integer filter radius or radii along y and x
  nomex  - [0] if true perform computation in matlab (for testing/timing)

  J      - [hxwxk] max image

  I = single(imResample(imread('cameraman.tif'),[480 640]))/255;
  r = 5; % set parameter as desired
  tic, J1=convMax(I,r); toc % mex version (fast)
  tic, J2=convMax(I,r,1); toc % matlab version (slow)
  figure(1); im(J1); figure(2); im(abs(J2-J1));

 See also conv2, convTri, convBox

 Piotr's Computer Vision Matlab Toolbox      Version 3.00
 Copyright 2014 Piotr Dollar & Ron Appel.  []
 Licensed under the Simplified BSD License [see external/bsd.txt]

Generated by m2html © 2003