[go: up one dir, main page]

Menu

[r999]: / Segtool / GetRefProfiles.py  Maximize  Restore  History

Download this file

105 lines (77 with data), 2.5 kB

  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
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 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
100
101
#!/usr/bin/env python
#
# Copyright (c) Madrid 2008
# BIT, ETSI Telecomunicacion, UPM
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#
#
modules = {'Section' : [0, '', 'none://Section.py' ]
}
import wx
import os
import sys
import string
from lxml import etree
from Section import *
def GetRelative(registered, segmented):
if len(registered) != len(segmented):
raise ValueError("both sets shoudl havethe same size")
result = []
for i in range(len(registered)):
delta = registered[i] - segmented[i]
result.append( ( 1.0 + delta * delta) / ( 1.0 + segmented[i] * segmented[i])
return result
app = wx.App()
file = open(sys.argv[1], "r")
strset = file.read()
root = etree.XML(strset)
file.close()
set = WorkSet(node=root)
slice_nr = string.atoi(sys.argv[2])
if slice_nr >= set.GetFrameNumber():
print "Frame number %d not from range:[0-%d)" % (slice_nr, set.GetFrameNumber())
exit(1)
if len(sys.argv) > 3:
zoom = atof(sys.argv[3])
else:
zoom = 1.0
if len(sys.argv) > 4:
shift = atof(sys.argv[4])
else:
shift = 0.0
masks = []
slice = set.GetFrame(slice_nr)
image = slice.GetImageZoomed(zoom)
size = image.GetSize()
for sec in slice.Sections:
masks.append(sec.GetMask(size, zoom))
for i in range(set.GetFrameNumber()):
frame = set.GetFrame(i)
image = frame.GetImageZoomed(zoom)
p_ref = frame.GetMaskedIntensities(zoom)
if len(p_ref) != 6:
print "slice %d not segmented like it should be" % i
exit(2)
p = []
for mask in masks:
val = 0.0
n = len(mask)
for m in mask:
val = val + image.GetRed(m[0], m[1])
p.append(val / n - shift)
res = GetRelative(p, p_ref):
print "%f %f %f %f %f %f" % (res[0], res[1], res[2], res[3], res[4], res[5])