File: nimage.rb

package info (click to toggle)
libnarray-ruby 0.5.9-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 564 kB
  • ctags: 564
  • sloc: ansic: 4,620; ruby: 1,513; python: 70; makefile: 5
file content (51 lines) | stat: -rw-r--r-- 885 bytes parent folder | download | duplicates (2)
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
require "narray"
require "nimage_c"

def NImage.show image

  r1 = image.min
  r2 = image.max
  b  = NArray.byte(*image.shape)
  b[]= (image.to_f-r1)/(r2-r1)*(NImage.ncolors-1)

  NImage.new b.to_s, *b.shape
end

def NImage.standard_color
  ncol = 32/4
  t = NArray.byte(ncol).indgen! * (255.0/ncol)
  r = NArray.byte(ncol,4)
  g = NArray.byte(ncol,4)
  b = NArray.byte(ncol,4)

  # Color map
  r[0..-1,1] = 
    g[0..-1,2] = 
    b[0..-1,0] = 
    b[-1..0,1] = 
    b[0..-1,3] = t
  r[0..-1,2] = 
    r[0..-1,3] = 
    g[0..-1,3] = 255

  NImage.colormap r.to_s, g.to_s, b.to_s
end

# Initalize colormap
#NImage.standard_color

#
#    TEST TEST TEST
#
if __FILE__ == $0

  x = NArray.sfloat(200,1).indgen!(-100)/50*3.1415
  y = NArray.sfloat(1,200).indgen!(-100)/50*3.1415
  z = NMath.cos(x) * NMath.sin(y)

  v = NImage.show z

  print "Hit return key..."
  STDIN.getc
  v.close
end