rimageanalysistools 5.1.2-java

Sign up to get free protection for your applications and to get access to all the features.
Binary file
@@ -0,0 +1,33 @@
1
+ #--
2
+ # /* ***** BEGIN LICENSE BLOCK *****
3
+ # *
4
+ # * Copyright (c) 2012 Colin J. Fuller
5
+ # *
6
+ # * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # * of this software and associated documentation files (the Software), to deal
8
+ # * in the Software without restriction, including without limitation the rights
9
+ # * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # * copies of the Software, and to permit persons to whom the Software is
11
+ # * furnished to do so, subject to the following conditions:
12
+ # *
13
+ # * The above copyright notice and this permission notice shall be included in
14
+ # * all copies or substantial portions of the Software.
15
+ # *
16
+ # * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # * SOFTWARE.
23
+ # *
24
+ # * ***** END LICENSE BLOCK ***** */
25
+ #++
26
+
27
+ require 'rimageanalysistools/initjava'
28
+
29
+ require 'edu/stanford/cfuller/imageanalysistools/resources/common_methods'
30
+
31
+
32
+
33
+
@@ -0,0 +1,72 @@
1
+ #--
2
+ # /* ***** BEGIN LICENSE BLOCK *****
3
+ # *
4
+ # * Copyright (c) 2012 Colin J. Fuller
5
+ # *
6
+ # * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # * of this software and associated documentation files (the Software), to deal
8
+ # * in the Software without restriction, including without limitation the rights
9
+ # * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # * copies of the Software, and to permit persons to whom the Software is
11
+ # * furnished to do so, subject to the following conditions:
12
+ # *
13
+ # * The above copyright notice and this permission notice shall be included in
14
+ # * all copies or substantial portions of the Software.
15
+ # *
16
+ # * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # * SOFTWARE.
23
+ # *
24
+ # * ***** END LICENSE BLOCK ***** */
25
+ #++
26
+
27
+ require 'rimageanalysistools'
28
+ require 'rimageanalysistools/image_shortcuts'
29
+
30
+ java_import Java::edu.stanford.cfuller.imageanalysistools.image.ImageCoordinate
31
+
32
+ module RImageAnalysisTools
33
+
34
+ class Centroids
35
+
36
+ def self.calculate_centroids_2d(mask)
37
+
38
+ centroids = {}
39
+ counts = {}
40
+
41
+ mask.each do |ic|
42
+
43
+ next unless mask[ic] > 0
44
+
45
+ unless centroids[mask[ic]] then
46
+
47
+ centroids[mask[ic]]= [0.0,0.0]
48
+ counts[mask[ic]]= 0
49
+
50
+ end
51
+
52
+ centroids[mask[ic]][0]+= ic.get(ImageCoordinate::X)
53
+ centroids[mask[ic]][1]+= ic.get(ImageCoordinate::Y)
54
+
55
+ counts[mask[ic]]+= 1
56
+
57
+ end
58
+
59
+ centroids.each_key do |k|
60
+
61
+ centroids[k].map! { |e| e/counts[k] }
62
+
63
+ end
64
+
65
+ centroids
66
+
67
+ end
68
+
69
+ end
70
+
71
+ end
72
+
@@ -0,0 +1,61 @@
1
+ #--
2
+ # /* ***** BEGIN LICENSE BLOCK *****
3
+ # *
4
+ # * Copyright (c) 2012 Colin J. Fuller
5
+ # *
6
+ # * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # * of this software and associated documentation files (the Software), to deal
8
+ # * in the Software without restriction, including without limitation the rights
9
+ # * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # * copies of the Software, and to permit persons to whom the Software is
11
+ # * furnished to do so, subject to the following conditions:
12
+ # *
13
+ # * The above copyright notice and this permission notice shall be included in
14
+ # * all copies or substantial portions of the Software.
15
+ # *
16
+ # * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # * SOFTWARE.
23
+ # *
24
+ # * ***** END LICENSE BLOCK ***** */
25
+ #++
26
+
27
+ require 'rimageanalysistools/initjava'
28
+
29
+ java_import Java::edu.stanford.cfuller.imageanalysistools.meta.parameters.ParameterDictionary
30
+
31
+ class ParameterDictionary
32
+
33
+ def [](key)
34
+ getValueForKey(key.to_s)
35
+ end
36
+
37
+ def []=(key, value)
38
+ setValueForKey(key.to_s, value.to_s)
39
+ end
40
+
41
+ end
42
+
43
+ module RImageAnalysisTools
44
+
45
+
46
+ def self.create_parameter_dictionary(parameter_hash)
47
+
48
+ p = ParameterDictionary.emptyDictionary
49
+
50
+ parameter_hash.each do |k,v|
51
+ p[k]= v
52
+ end
53
+
54
+ p
55
+
56
+ end
57
+
58
+
59
+
60
+ end
61
+
@@ -0,0 +1,65 @@
1
+ #--
2
+ # /* ***** BEGIN LICENSE BLOCK *****
3
+ # *
4
+ # * Copyright (c) 2012 Colin J. Fuller
5
+ # *
6
+ # * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # * of this software and associated documentation files (the Software), to deal
8
+ # * in the Software without restriction, including without limitation the rights
9
+ # * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # * copies of the Software, and to permit persons to whom the Software is
11
+ # * furnished to do so, subject to the following conditions:
12
+ # *
13
+ # * The above copyright notice and this permission notice shall be included in
14
+ # * all copies or substantial portions of the Software.
15
+ # *
16
+ # * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # * SOFTWARE.
23
+ # *
24
+ # * ***** END LICENSE BLOCK ***** */
25
+ #++
26
+
27
+ module RImageAnalysisTools
28
+
29
+ class DirWalker
30
+
31
+ include Enumerable
32
+
33
+ def initialize(base_path, exclude_hidden = true)
34
+
35
+ @base_path = base_path
36
+ @exclude_hidden = exclude_hidden
37
+
38
+ end
39
+
40
+ def each
41
+
42
+ walk_path("") do |ext, f|
43
+
44
+ yield @base_path + ext + f
45
+
46
+ end
47
+
48
+ end
49
+
50
+ def walk_path(extra)
51
+
52
+ Dir.foreach(@base_path + extra) do |f|
53
+ if @exclude_hidden and f.start_with?(".") then
54
+ next
55
+ end
56
+ if File.directory?(@base_path + extra + f) then
57
+ walk_path(@base_path, extra + f + File::Separator) do |ext_rec, f_rec|
58
+ yield ext_rec, f_rec
59
+ end
60
+ else
61
+ yield extra, f
62
+ end
63
+ end
64
+
65
+ end
@@ -0,0 +1,158 @@
1
+ #--
2
+ # /* ***** BEGIN LICENSE BLOCK *****
3
+ # *
4
+ # * Copyright (c) 2012 Colin J. Fuller
5
+ # *
6
+ # * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # * of this software and associated documentation files (the Software), to deal
8
+ # * in the Software without restriction, including without limitation the rights
9
+ # * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # * copies of the Software, and to permit persons to whom the Software is
11
+ # * furnished to do so, subject to the following conditions:
12
+ # *
13
+ # * The above copyright notice and this permission notice shall be included in
14
+ # * all copies or substantial portions of the Software.
15
+ # *
16
+ # * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # * SOFTWARE.
23
+ # *
24
+ # * ***** END LICENSE BLOCK ***** */
25
+ #++
26
+
27
+ require 'rimageanalysistools'
28
+ require 'rimageanalysistools/image_shortcuts'
29
+
30
+ java_import Java::edu.stanford.cfuller.imageanalysistools.image.ReadOnlyImageImpl
31
+
32
+ class ReadOnlyImageImpl
33
+
34
+ def box_conservative(lower, upper, dims)
35
+
36
+ low_curr = nil
37
+ up_curr = nil
38
+
39
+ if getIsBoxed then
40
+
41
+ low_curr = getBoxMin
42
+ up_curr = getBoxMax
43
+
44
+ else
45
+
46
+ low_curr = ImageCoordinate[0,0,0,0,0]
47
+ up_curr = ImageCoordinate.cloneCoord(getDimensionSizes)
48
+
49
+ end
50
+
51
+ dims.each do |d|
52
+ low_curr[d]= lower[d]
53
+ up_curr[d]= upper[d]
54
+ end
55
+
56
+ end
57
+
58
+ end
59
+
60
+ module RImageAnalysisTools
61
+
62
+ class Drawing
63
+
64
+ def draw(im, draw_value = 255.0)
65
+
66
+ im.each do |ic|
67
+
68
+ if (yield ic) then
69
+
70
+ im.setValue(ic, draw_value)
71
+
72
+ end
73
+
74
+ end
75
+
76
+ end
77
+
78
+ def draw_shape(im, location, shape_name=:circle, shape_parameters= 10)
79
+
80
+ if self.respond_to?(shape_name) then
81
+
82
+ self.send(shape_name, im, location, shape_parameters)
83
+
84
+ end
85
+
86
+ end
87
+
88
+ def circle(im, center, radius)
89
+
90
+ lower = ImageCoordinate[center[0]-radius-1, center[1]-radius-1, 0,0,0]
91
+ upper = ImageCoordinate[center[0]+radius+1, center[1]+radius+1, 0,0,0]
92
+
93
+ im.box_conservative(lower, upper, [:x, :y])
94
+
95
+ draw(im) do |ic|
96
+
97
+ xdiff = ic[:x] - center[0]
98
+ ydiff = ic[:y] - center[1]
99
+
100
+ if (Math.hypot(xdiff, ydiff) - radius).abs <= Math.sqrt(2) then
101
+ true
102
+ else
103
+ false
104
+ end
105
+
106
+ end
107
+
108
+ lower.recycle
109
+ upper.recycle
110
+
111
+ end
112
+
113
+ def ellipse(im, foci, radius_inc)
114
+
115
+ min_x = foci[0][0]
116
+ max_x = foci[1][0]
117
+ min_y = foci[0][1]
118
+ max_y = foci[1][1]
119
+
120
+ if foci[1][0] < min_x then
121
+ min_x = foci[1][0]
122
+ max_x = foci[0][0]
123
+ end
124
+
125
+ if foci[1][1] < min_y then
126
+ min_y = foci[1][1]
127
+ max_y = foci[0][1]
128
+ end
129
+
130
+ radius = radius_inc + Math.hypot(max_x-min_x, max_y-min_y)
131
+
132
+ lower = ImageCoordinate[min_x-radius-1, min_y-radius-1, 0,0,0]
133
+ upper = ImageCoordinate[max_x+radius+1, max_y+radius+1, 0,0,0]
134
+
135
+ im.box_conservative(lower, upper, [:x, :y])
136
+
137
+ draw(im) do |ic|
138
+
139
+ xdiff0 = ic[:x] - foci[0][0]
140
+ ydiff0 = ic[:y] - foci[0][1]
141
+ xdiff1 = ic[:x] - foci[1][0]
142
+ ydiff1 = ic[:y] - foci[1][1]
143
+
144
+ if (Math.hypot(xdiff0, ydiff0) + Math.hypot(xdiff1, ydiff1) - radius).abs <= Math.sqrt(2) then
145
+ true
146
+ else
147
+ false
148
+ end
149
+
150
+ end
151
+
152
+
153
+ end
154
+
155
+
156
+ end
157
+
158
+ end
@@ -0,0 +1,45 @@
1
+ #--
2
+ # /* ***** BEGIN LICENSE BLOCK *****
3
+ # *
4
+ # * Copyright (c) 2013 Colin J. Fuller
5
+ # *
6
+ # * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # * of this software and associated documentation files (the Software), to deal
8
+ # * in the Software without restriction, including without limitation the rights
9
+ # * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # * copies of the Software, and to permit persons to whom the Software is
11
+ # * furnished to do so, subject to the following conditions:
12
+ # *
13
+ # * The above copyright notice and this permission notice shall be included in
14
+ # * all copies or substantial portions of the Software.
15
+ # *
16
+ # * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # * SOFTWARE.
23
+ # *
24
+ # * ***** END LICENSE BLOCK ***** */
25
+ #++
26
+
27
+ require 'rimageanalysistools'
28
+
29
+ java_import Java::edu.stanford.cfuller.imageanalysistools.fitting.BisquareLinearFit
30
+
31
+ java_import Java::org.apache.commons.math3.linear.ArrayRealVector
32
+
33
+ class BisquareLinearFit
34
+
35
+ def fit_rb(x, y)
36
+
37
+ x_vec = ArrayRealVector.new(x.to_a.to_java(:double))
38
+ y_vec = ArrayRealVector.new(y.to_a.to_java(:double))
39
+
40
+ fit(x_vec, y_vec)
41
+
42
+ end
43
+
44
+ end
45
+
@@ -0,0 +1,43 @@
1
+ #--
2
+ # /* ***** BEGIN LICENSE BLOCK *****
3
+ # *
4
+ # * Copyright (c) 2012 Colin J. Fuller
5
+ # *
6
+ # * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # * of this software and associated documentation files (the Software), to deal
8
+ # * in the Software without restriction, including without limitation the rights
9
+ # * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # * copies of the Software, and to permit persons to whom the Software is
11
+ # * furnished to do so, subject to the following conditions:
12
+ # *
13
+ # * The above copyright notice and this permission notice shall be included in
14
+ # * all copies or substantial portions of the Software.
15
+ # *
16
+ # * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # * SOFTWARE.
23
+ # *
24
+ # * ***** END LICENSE BLOCK ***** */
25
+ #++
26
+
27
+ require 'rimageanalysistools/initjava'
28
+ java_import Java::edu.stanford.cfuller.imageanalysistools.filter.Filter
29
+
30
+ module RImageAnalysisTools
31
+
32
+ Filter_package_name = "edu.stanford.cfuller.imageanalysistools.filter."
33
+
34
+ def self.get_filter(filter_name)
35
+
36
+ java_import (Filter_package_name + filter_name.to_s)
37
+
38
+ const_get(filter_name).new
39
+
40
+ end
41
+
42
+
43
+ end