File: create_split_image.py

package info (click to toggle)
openstructure 2.11.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 206,256 kB
  • sloc: cpp: 188,571; python: 36,686; ansic: 34,298; fortran: 3,275; sh: 312; xml: 146; makefile: 29
file content (44 lines) | stat: -rw-r--r-- 1,472 bytes parent folder | download | duplicates (4)
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
import sys
from math import *
from ost.img.alg import *
from ost.geom import *


def CreateSplitImage(imagelist, start_at_y=True):
    result=imagelist[0].Copy(False)
    result.CenterSpatialOrigin()
    extent=imagelist[0].GetExtent()
    if start_at_y:
        startpoint=Vec2(0.0,-extent.GetSize()[0])
    else:
        startpoint=Vec2(extent.GetSize()[0],0.0)
    angle=2*pi/len(imagelist)
    count=0
    for image in imagelist:
        image.CenterSpatialOrigin()
        start_angle=angle*count
        end_angle=angle*(count+1)
        pol=Polygon2()
        pol.AddNode(Vec2(0,0))
        pol.AddNode(Rotate(startpoint,start_angle))
        if(start_angle<pi/4.0 and end_angle>pi/4.0):
            pol.AddNode(Rotate(startpoint,pi/4.0))
        if(start_angle<3.0*pi/4.0 and end_angle>3.0*pi/4.0):
            pol.AddNode(Rotate(startpoint,3.0*pi/4.0))
        if(start_angle<5.0*pi/4.0 and end_angle>5.0*pi/4.0):
            pol.AddNode(Rotate(startpoint,5.0*pi/4.0))
        if(start_angle<7.0*pi/4.0 and end_angle>7.0*pi/4.0):
            pol.AddNode(Rotate(startpoint,7.0*pi/4.0))
        pol.AddNode(Rotate(startpoint,end_angle))
        m=img.Mask(pol)
        result+=image.Apply(img.alg.MaskImage(m))
        count+=1
    return result

if len(sys.argv)<3:
  imagelist=io.LoadImageList(['circle.png', 'square.png'])
else:
  imagelist=io.LoadImageList(sys.argv[1:-1])

result=CreateSplitImage(imagelist)
v_result=gui.CreateDataViewer(result,"Split Image")