Login  Register

Re: Convolution kernels

Posted by Robert Dougherty on Feb 26, 2009; 5:13pm
URL: http://imagej.273.s1.nabble.com/Convolution-kernels-tp3693561p3693562.html

Prof. Knecht,

Looking under the hood, the convolution code starts by making a copy  
of the image.  It then replaces each pixel of the original image by a  
computation made from the copy.  This is how it should be.  I wonder  
about your test methodology.  As for the edges, I had assumed zero-
padding, but it is actually more interesting.  The input image is  
effectively extended by duplicating the edge pixels outward,  
perpendicular to the image.  The corner areas are effectively filled  
with the value of the corner pixel.  Here is the code to get a pixel  
from location (x,y) to use in the convolution.  If x is outside the  
image, then x is replaced with the closest x that is part of the  
image, and similarly for y.

     private float getPixel(int x, int y, float[] pixels, int width,  
int height) {
         if (x<=0) x = 0;
         if (x>=width) x = width-1;
         if (y<=0) y = 0;
         if (y>=height) y = height-1;
         return pixels[x+y*width];
     }

Bob

On Feb 26, 2009, at 8:01 AM, David Knecht wrote:

> I am trying to understand how a convolution like a 2x2 mean filter  
> actually works.  I presume it always starts in the upper left of the  
> image.  It would then calculate the average of those first 4  
> pixels.  I thought that the sliding window of the convolution resets  
> as it moves so that you are always calculating from the original  
> values of the image matrix as opposed to using the new calculated  
> value from applying the convolution.  I ran a test to confirm, and  
> to my surprise it appears that the convolution is applied  
> continuously. Is that right?  Is this described somewhere in the  
> documentation?  I would imagine that you could filter either way and  
> it is just how the algorithm is implemented.  Also, is it described  
> somewhere how imageJ handle the edges?  Dave
>
> Dr. David Knecht
> Department of Molecular and Cell Biology
> Co-head Flow Cytometry and Confocal Microscopy Facility
> U-3125
> 91 N. Eagleville Rd.
> University of Connecticut
> Storrs, CT 06269
> 860-486-2200
> 860-486-4331 (fax)

Robert Dougherty, Ph.D.
President, OptiNav, Inc.
4176 148th Ave. NE
Redmond, WA 98052
(425)891-4883
FAX (425)467-1119
www.optinav.com
[hidden email]