OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
create_split_image.py

This scripts loads one or more images and creates a split image where each of the images is displayed in a cone of equal angle.

Usage:

dng create_split_image.py <input image 1> [<input image 2> <input image 3> .... ] <output image>



1 import sys
2 from math import *
3 from ost.img.alg import *
4 from ost.geom import *
5 
6 
7 def CreateSplitImage(imagelist, start_at_y=True):
8  result=imagelist[0].Copy(False)
9  result.CenterSpatialOrigin()
10  extent=imagelist[0].GetExtent()
11  if start_at_y:
12  startpoint=Vec2(0.0,-extent.GetSize()[0])
13  else:
14  startpoint=Vec2(extent.GetSize()[0],0.0)
15  angle=2*pi/len(imagelist)
16  count=0
17  for image in imagelist:
18  image.CenterSpatialOrigin()
19  start_angle=angle*count
20  end_angle=angle*(count+1)
21  pol=Polygon2()
22  pol.AddNode(Vec2(0,0))
23  pol.AddNode(Rotate(startpoint,start_angle))
24  if(start_angle<pi/4.0 and end_angle>pi/4.0):
25  pol.AddNode(Rotate(startpoint,pi/4.0))
26  if(start_angle<3.0*pi/4.0 and end_angle>3.0*pi/4.0):
27  pol.AddNode(Rotate(startpoint,3.0*pi/4.0))
28  if(start_angle<5.0*pi/4.0 and end_angle>5.0*pi/4.0):
29  pol.AddNode(Rotate(startpoint,5.0*pi/4.0))
30  if(start_angle<7.0*pi/4.0 and end_angle>7.0*pi/4.0):
31  pol.AddNode(Rotate(startpoint,7.0*pi/4.0))
32  pol.AddNode(Rotate(startpoint,end_angle))
33  m=img.Mask(pol)
34  result+=image.Apply(img.alg.MaskImage(m))
35  count+=1
36  return result
37 
38 if len(sys.argv)<3:
39  imagelist=io.LoadImageList(['circle.png', 'square.png'])
40 else:
41  imagelist=io.LoadImageList(sys.argv[1:-1])
42 
43 result=CreateSplitImage(imagelist)
44 v_result=gui.CreateDataViewer(result,"Split Image")