-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSobel_transform.ijm
57 lines (48 loc) · 1.31 KB
/
Sobel_transform.ijm
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
img = getTitle();
mag_title = img + " (sobel_mag)"
phase_title = img + " (sobel_phase)"
selectWindow(img);
run("Duplicate...", "title=sobel_x");
run("32-bit");
run("Convolve...", "text1=[1 0 -1\n2 0 -2\n1 0 -1\n] normalize");
run("Duplicate...", "title=sobel_x2");
run("Square");
selectWindow(img);
run("Duplicate...", "title=sobel_y");
run("32-bit");
run("Convolve...", "text1=[1 2 1\n0 0 0\n-1 -2 -1\n] normalize");
run("Duplicate...", "title=sobel_y2");
run("Square");
imageCalculator("Add create 32-bit", "sobel_x2","sobel_y2");
selectWindow("Result of sobel_x2");
run("Square Root");
run("Enhance Contrast...", "saturated=0.0");
rename(mag_title);
close("sobel_x2");
close("sobel_y2");
selectImage("sobel_x");
w = getWidth();
h = getHeight();
x_img = newArray(w*h);
y_img = newArray(w*h);
for (y=0; y<h; y++) {
for (x=0; x<w; x++) {
x_img[x+(w*y)]=getPixel(x, y);
}
}
selectImage("sobel_y");
for (y=0; y<h; y++) {
for (x=0; x<w; x++) {
y_img[x+(w*y)]=getPixel(x, y);
}
}
newImage(phase_title, "32-bit", w, h, 1);
for (y=0; y<h; y++) {
for (x=0; x<w; x++) {
setPixel(x, y, atan2(y_img[x+(w*y)],x_img[x+(w*y)]));
}
}
updateDisplay();
run("Enhance Contrast...", "saturated=0.0");
close("sobel_x");
close("sobel_y");