Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
Shadows.java
1 package ij.plugin.filter;
2 import ij.*;
3 import ij.gui.*;
4 import ij.process.*;
5 import java.awt.*;
6 
8 public class Shadows implements PlugInFilter {
9 
10  String arg;
11  ImagePlus imp;
12 
13  public int setup(String arg, ImagePlus imp) {
14  this.arg = arg;
15  this.imp = imp;
16  if (imp!=null && imp.getStackSize()>1 && arg.equals("demo"))
17  {IJ.error("This demo does not work with stacks."); return DONE;}
19  }
20 
21  public void run(ImageProcessor ip) {
22  if (arg.equals("north")) north(ip);
23  else if (arg.equals("northeast")) northeast(ip);
24  else if (arg.equals("east")) east(ip);
25  else if (arg.equals("southeast")) southeast(ip);
26  else if (arg.equals("south")) south(ip);
27  else if (arg.equals("southwest")) southwest(ip);
28  else if (arg.equals("west")) west(ip);
29  else if (arg.equals("northwest")) northwest(ip);
30 
31  }
32 
33 
34  public void north(ImageProcessor ip) {
35  int[] kernel = {1,2,1, 0,1,0, -1,-2,-1};
36  ip.convolve3x3(kernel);
37  }
38 
39  public void south(ImageProcessor ip) {
40  int[] kernel = {-1,-2,-1, 0,1,0, 1,2,1};
41  ip.convolve3x3(kernel);
42  }
43 
44  public void east(ImageProcessor ip) {
45  int[] kernel = {-1,0,1, -2,1,2, -1,0,1};
46  ip.convolve3x3(kernel);
47  }
48 
49  public void west(ImageProcessor ip) {
50  int[] kernel = {1,0,-1, 2,1,-2, 1,0,-1};
51  ip.convolve3x3(kernel);
52  }
53 
54  public void northwest(ImageProcessor ip) {
55  int[] kernel = {2,1,0, 1,1,-1, 0,-1,-2};
56  ip.convolve3x3(kernel);
57  }
58 
59  public void southeast(ImageProcessor ip) {
60  int[] kernel = {-2,-1,0, -1,1,1, 0,1,2};
61  ip.convolve3x3(kernel);
62  }
63 
64  public void northeast(ImageProcessor ip) {
65  int[] kernel = {0,1,2, -1,1,1, -2,-1,0};
66  ip.convolve3x3(kernel);
67  }
68 
69  public void southwest(ImageProcessor ip) {
70  int[] kernel = {0,-1,-2, 1,1,-1, 2,1,0};
71  ip.convolve3x3(kernel);
72  }
73 }