OTO - Ohshima Tamashima Observatory- - test_narray Diff
- Added parts are displayed like this.
- Deleted parts are displayed
like this.
!NArrayのテスト
<<<
equire 'narray'
# make a test image
@im=@im2=NArray.int(10,10).fill!(0)
for x in 3..7
for y in 2..6
@im[x,y]=2
end
end
@im[5,5]=10
@im[4,5]=5
@im[6,5]=8
p @im.dim
p @im.shape
p @im.sum
p @im.sum(0..1)
p @im.sum(1)
p @im.sort
p a=@im.sort_index #indexを要素にもつarray
p a[a.max] #maxのindex
p @im[a[a.max]] #maxのピクセルの値
p @im.max #maxの値
>>>
結果
<<<
o2@am2:~/ruby/fits$ ruby testArry.rb
2
[10, 10]
67
67
NArray.int(10):
[ 0, 0, 0, 10, 13, 18, 16, 10, 0, 0 ]
NArray.int(10,10):
[ [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 2, 2, 2, 2, 2 ],
[ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ],
[ 2, 2, 2, 2, 2, 2, 2, 5, 8, 10 ] ]
NArray.int(10,10):
[ [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ],
[ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 ],
[ 20, 21, 22, 28, 29, 30, 31, 32, 38, 39 ],
[ 40, 41, 42, 48, 49, 50, 51, 52, 58, 59 ],
[ 60, 61, 62, 68, 69, 70, 71, 72, 73, 74 ],
[ 75, 76, 77, 78, 79, 80, 81, 82, 83, 84 ],
[ 85, 86, 87, 88, 89, 90, 91, 92, 93, 94 ],
[ 95, 96, 97, 98, 99, 23, 24, 25, 26, 27 ],
[ 33, 34, 35, 36, 37, 43, 44, 45, 46, 47 ],
[ 53, 57, 63, 64, 65, 66, 67, 54, 56, 55 ] ]
55
10
10
>>>
<<<
require 'narray'
def leftHandSearch(x,y,dxp,dyp) #再帰を使った連続領域範囲の探査
# puts "("+x.to_s+","+y.to_s+")"
@ary[[x,y]]=-1 #探査済み領域はー1とする
if@miny>y then @miny=y end #星像範囲設定
if@maxx<x then @maxx=x end
if@maxy<y then @maxy=y end
if@minx>x then @minx=x end
if ((@im[x+dxp,y+dyp]>@thres)&&(@ary[[x+dxp,y+dyp]]!=-1))
leftHandSearch(x+dxp,y+dyp, dxp, dyp) #直進してよい場合
else #右へ回れ(実際の画像の座標系では、左回りになる)
dxf=dyp
dyf=(-1)*dxp
if ((@im[x+dxf,y+dyf]>@thres)&&(@ary[[x+dxf,y+dyf]]!=-1))
leftHandSearch(x+dxf,y+dyf, dxf, dyf)
end
end
end
# make a test image
@im=@im2=NArray.int(10,10).fill!(0)
for x in3..7 0..4
for y in2..60..4
@im[x,y]=2
end
end
@im[5,5]=10@im[2,2]=8
@im[4,5]=5for x in 5..9
for y in 5..9
@im[x,y]=3
end
end
@im[6,5]=8@im[7,7]=9
p @im
p @im[@im.max]
@ary=Hash.new #探査済み領域チェック用
@maxx=@maxy=0
@minx=@miny=10000
@gx_sum=@gy_sum=@im_sum=0
@thres=1 #星像検出の閾値
leftHandSearch(5,5,1,0)leftHandSearch(2,2,1,0)
#puts @minx,@maxx,@miny,@maxy #連続領域範囲
(@minx..@maxx).each do |x|
(@miny..@maxy).each do |y|
@gx_sum = @gx_sum + x*@im[x,y]
@gy_sum = @gy_sum + y*@im[x,y]
@im_sum = @im_sum + @im[x,y]
end
end
gx = @gx_sum/@im_sum #星像の重心計算
gy=@gy_sum/@im_sum
puts "("+gx.to_s+","+gy.to_s+")"
>>>
<<<
o2@am2:~/ruby/fits$ ruby testArry2.rb
NArray.int(10,10):
[ [ 0, 0, 0, 0, 0, 0, 0,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, 90, 91, 92, 93, 94 ],
[ 95, 96, 97, 98, 99, 23, 24, 25, 26, 27 ],
[ 33, 34, 35, 36, 37, 43, 44, 45, 46, 47 ],
[ 53, 57, 63, 64, 65, 66, 67, 54, 56, 55 ] ]
55
10
10
o2@am2:~/ruby/fits$ ruby testArry2.rb
NArray.int(10,10):
[ [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 2, 2, 2, 2, 2, 0, 0 ],
[ 0, 0, 0, 2, 2, 2, 2, 2, 0, 0 ],
[ 0, 0, 0, 2, 2, 2, 2, 2, 0, 0 ],
[ 0, 0, 0, 2, 5, 10, 8, 2, 0, 0 ],
[ 0, 0, 0, 2, 2, 2, 2, 2, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ]
0
(5,4)
>>>
<<<
equire 'narray'
# make a test image
@im=@im2=NArray.int(10,10).fill!(0)
for x in 3..7
for y in 2..6
@im[x,y]=2
end
end
@im[5,5]=10
@im[4,5]=5
@im[6,5]=8
p @im.dim
p @im.shape
p @im.sum
p @im.sum(0..1)
p @im.sum(1)
p @im.sort
p a=@im.sort_index #indexを要素にもつarray
p a[a.max] #maxのindex
p @im[a[a.max]] #maxのピクセルの値
p @im.max #maxの値
>>>
結果
<<<
o2@am2:~/ruby/fits$ ruby testArry.rb
2
[10, 10]
67
67
NArray.int(10):
[ 0, 0, 0, 10, 13, 18, 16, 10, 0, 0 ]
NArray.int(10,10):
[ [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 2, 2, 2, 2, 2 ],
[ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ],
[ 2, 2, 2, 2, 2, 2, 2, 5, 8, 10 ] ]
NArray.int(10,10):
[ [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ],
[ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 ],
[ 20, 21, 22, 28, 29, 30, 31, 32, 38, 39 ],
[ 40, 41, 42, 48, 49, 50, 51, 52, 58, 59 ],
[ 60, 61, 62, 68, 69, 70, 71, 72, 73, 74 ],
[ 75, 76, 77, 78, 79, 80, 81, 82, 83, 84 ],
[ 85, 86, 87, 88, 89, 90, 91, 92, 93, 94 ],
[ 95, 96, 97, 98, 99, 23, 24, 25, 26, 27 ],
[ 33, 34, 35, 36, 37, 43, 44, 45, 46, 47 ],
[ 53, 57, 63, 64, 65, 66, 67, 54, 56, 55 ] ]
55
10
10
>>>
<<<
require 'narray'
def leftHandSearch(x,y,dxp,dyp) #再帰を使った連続領域範囲の探査
# puts "("+x.to_s+","+y.to_s+")"
@ary[[x,y]]=-1 #探査済み領域はー1とする
if@miny>y then @miny=y end #星像範囲設定
if@maxx<x then @maxx=x end
if@maxy<y then @maxy=y end
if@minx>x then @minx=x end
if ((@im[x+dxp,y+dyp]>@thres)&&(@ary[[x+dxp,y+dyp]]!=-1))
leftHandSearch(x+dxp,y+dyp, dxp, dyp) #直進してよい場合
else #右へ回れ(実際の画像の座標系では、左回りになる)
dxf=dyp
dyf=(-1)*dxp
if ((@im[x+dxf,y+dyf]>@thres)&&(@ary[[x+dxf,y+dyf]]!=-1))
leftHandSearch(x+dxf,y+dyf, dxf, dyf)
end
end
end
# make a test image
@im=@im2=NArray.int(10,10).fill!(0)
for x in
for y in
@im[x,y]=2
end
end
for y in 5..9
@im[x,y]=3
end
end
p @im
p @im[@im.max]
@ary=Hash.new #探査済み領域チェック用
@maxx=@maxy=0
@minx=@miny=10000
@gx_sum=@gy_sum=@im_sum=0
@thres=1 #星像検出の閾値
#puts @minx,@maxx,@miny,@maxy #連続領域範囲
(@minx..@maxx).each do |x|
(@miny..@maxy).each do |y|
@gx_sum = @gx_sum + x*@im[x,y]
@gy_sum = @gy_sum + y*@im[x,y]
@im_sum = @im_sum + @im[x,y]
end
end
gx = @gx_sum/@im_sum #星像の重心計算
gy=@gy_sum/@im_sum
puts "("+gx.to_s+","+gy.to_s+")"
>>>
<<<
o2@am2:~/ruby/fits$ ruby testArry2.rb
NArray.int(10,10):
[ [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 2, 2, 2, 2, 2, 0, 0 ],
[ 0, 0, 0, 2, 2, 2, 2, 2, 0, 0 ],
[ 0, 0, 0, 2, 2, 2, 2, 2, 0, 0 ],
[ 0, 0, 0, 2, 5, 10, 8, 2, 0, 0 ],
[ 0, 0, 0, 2, 2, 2, 2, 2, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ]
0
(5,4)
o2@am2:~/ruby/fits$ ruby testArry.rb
2
[10, 10]
67
67
NArray.int(10):
[ 0, 0, 0, 10, 13, 18, 16, 10, 0, 0 ]
NArray.int(10,10):
[ [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 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