June 10, 2004
This illustrates the general convolution operation, of which smooth, sharpen and shadow are specific instances.
Using a kernel supplied with Image
Modified kernel files that should work on both Mac and PC (and with ImageJ) are in the Sample Images / Kernels folder. (The files as downloaded with the NIH or Scion Image applications are in different locations on the Mac and on the PC.)

Original no convolution kernel
|
Sharpen SHRP3X3-12.TXT
|
<option> sharpen SHRP3X3-9.TXT
|
The SHRP3X3-12 kernel is the same as the Process -> Sharpen menu:
(This is the section about convolve from the NIH Image manual.)
Convolve
Does spatial convolutions using kernels read from a text file or text window. Kernels can be up to 63 x 63 in size. Output pixel values are clipped to 8-bits unless Scale Convolutions is checked in the Preferences dialog box. Use Image's built-in text editor to create or examine these kernels.
As an example, use the New command to open a blank text window, enter (or paste) the following kernel, then use the Convolve command to try it out.
0 0 0 -1 -1 -1 0 0 0 0 -1 -1 -3 -3 -3 -1 -1 0 0 -1 -3 -3 -1 -3 -3 -1 0 -1 -3 -3 6 13 6 -3 -3 -1 -1 -3 -1 13 24 13 -1 -3 -1 -1 -3 -3 6 13 6 -3 -3 -1 0 -1 -3 -3 -1 -3 -3 -1 0 0 -1 -1 -3 -3 -3 -1 -1 0 0 0 0 -1 -1 -1 0 0 0
This is a 9 x 9 "Mexican hat" filter which will do both smoothing and edge detection in one operation. Each line should be terminated with a carriage return, and the coefficients should be separated by one or more spaces, or a tab. Note that kernels, such as this one, can be opened and displayed as an image using the Import (Text) command, scaled to a reasonable size using Scale and Rotate, and plotted using the Surface Plot command.
(from ImageJ web page: " ... Note that kernels can be saved in a text file (using copy (control-C) and paste), displayed as an image using File/Import/As Text Image, scaled to a reasonable size using Image/Adjust/Size, and plotted using the Surface Plot plugin. (or Analyze / Surface Plot DSB)"
Mexican Hat Filter.:
Image
|
ImageJ
|
Note the 8 pixel wide border (measure with the cursor, looking at the Info window) around the edges. (17 = 1 + 2*8). (Not there in ImageJ)
To visualize the Mexican Hat kernel:
This is the unzoomed image of the 17x17 array of numbers. |
If the file were opened with the file -> Open menu file / Open, or File / Import / Text File, the resulting text window would look like this:
|
The image window is only 17 pixels on an edge. It can be zoomed, or it can be scaled. See the size exercise.
Image
|
ImageJ
|
This image is large enough to be conveniently viewed and false colored. For profile plots, however, it must be magnified by scaling. To see what I mean, using this zoomed image (which is still only 17x17 pixels:)
Image
|
I have moved the Plot window on top of the Hat image to show them together. Sometimes this is handy to do in practise. When a new line is being 'moused' in the image, the plot window will be covered because you have selected the image window. The plot window will reappear after the mouse button is released. (Note that high pixel values are black - the default Image interpretation.) |
|
ImageJ
|
![]() |
To see a satisfactory plot (not needed for ImageJ), scale the image, then repeat the profile plot steps:

Now, the profile tool behaves in the normal way.
Image
Keep the default size settings and the default wire frame option.. |
ImageJ: Use these settings:
|
Image
ImageJ
( Try other settings - the results are interesting. )
This is a surface plot of the pixel intensities of the 17x17 kernel. Each of the bocks represents one pixel in the original image, but a 16x16 pixel area in the scaled image used for the 3-D plot.
Other things to try: