File: Shadows.java

package info (click to toggle)
imagej 1.51i%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 5,244 kB
  • ctags: 13,220
  • sloc: java: 113,144; sh: 285; xml: 50; makefile: 8
file content (86 lines) | stat: -rw-r--r-- 2,393 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package ij.plugin.filter;
import ij.*;
import ij.gui.*;
import ij.process.*;
import java.awt.*;

/** Implements the commands in the Process/Shadows submenu. */
public class Shadows implements PlugInFilter {
	
	String arg;
	ImagePlus imp;

	public int setup(String arg, ImagePlus imp) {
		this.arg = arg;
		this.imp = imp;
		if (imp!=null && imp.getStackSize()>1 && arg.equals("demo"))
			{IJ.error("This demo does not work with stacks."); return DONE;}
		return IJ.setupDialog(imp, DOES_ALL+SUPPORTS_MASKING);
	}

	public void run(ImageProcessor ip) {
		if (arg.equals("demo")) {
			IJ.resetEscape();
			while (!IJ.escapePressed()) {
				north(ip); imp.updateAndDraw(); ip.reset();
				northeast(ip); imp.updateAndDraw(); ip.reset();
				east(ip); imp.updateAndDraw(); ip.reset();
				southeast(ip); imp.updateAndDraw(); ip.reset();
				south(ip); imp.updateAndDraw(); ip.reset();
				southwest(ip); imp.updateAndDraw(); ip.reset();
				west(ip); imp.updateAndDraw(); ip.reset();
				northwest(ip); imp.updateAndDraw(); ip.reset();
			}
		}
		else if (arg.equals("north")) north(ip);
		else if (arg.equals("northeast")) northeast(ip);
		else if (arg.equals("east")) east(ip);
		else if (arg.equals("southeast")) southeast(ip);
		else if (arg.equals("south")) south(ip);
		else if (arg.equals("southwest")) southwest(ip);
		else if (arg.equals("west")) west(ip);
		else if (arg.equals("northwest")) northwest(ip);

	}
		
		
		public void north(ImageProcessor ip) {
			int[] kernel = {1,2,1, 0,1,0,  -1,-2,-1};
			ip.convolve3x3(kernel);
		}

		public void south(ImageProcessor ip) {
			int[] kernel = {-1,-2,-1,  0,1,0,  1,2,1};
			ip.convolve3x3(kernel);
		}

		public void east(ImageProcessor ip) {
			int[] kernel = {-1,0,1,  -2,1,2,  -1,0,1};
			ip.convolve3x3(kernel);
		}

		public void west(ImageProcessor ip) {
			int[] kernel = {1,0,-1,  2,1,-2,  1,0,-1};
			ip.convolve3x3(kernel);
		}

		public void northwest(ImageProcessor ip) {
			int[] kernel = {2,1,0,  1,1,-1,  0,-1,-2};
			ip.convolve3x3(kernel);
		}

		public void southeast(ImageProcessor ip) {
			int[] kernel = {-2,-1,0,  -1,1,1,  0,1,2};
			ip.convolve3x3(kernel);
		}
		
		public void northeast(ImageProcessor ip) {
			int[] kernel = {0,1,2,  -1,1,1,  -2,-1,0};
			ip.convolve3x3(kernel);
		}
		
		public void southwest(ImageProcessor ip) {
			int[] kernel = {0,-1,-2,  1,1,-1,  2,1,0};
			ip.convolve3x3(kernel);
		}
}