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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319
|
#############################################################################
##
## Copyright (C) 2006-2007 University of Utah. All rights reserved.
##
## This file is part of VisTrails.
##
## This file may be used under the terms of the GNU General Public
## License version 2.0 as published by the Free Software Foundation
## and appearing in the file LICENSE.GPL included in the packaging of
## this file. Please review the following to ensure GNU General Public
## Licensing requirements will be met:
## http://www.opensource.org/licenses/gpl-license.php
##
## If you are unsure which license is appropriate for your use (for
## instance, you are interested in developing a commercial derivative
## of VisTrails), please contact us at contact@vistrails.org.
##
## This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
## WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
##
############################################################################
import itk
import core.modules
from core.modules.vistrails_module import Module, ModuleError
from ITK import *
from Image import Image
class IsolatedWatershedImageFilter(Module):
my_namespace="Filter|Segmentation"
def compute(self):
im = self.getInputFromPort("Input Image")
#check for input PixelType
if self.hasInputFromPort("Input PixelType"):
inPixelType = self.getInputFromPort("Input PixelType")
else:
inPixelType = im.getPixelType()
#check for output PixelType
if self.hasInputFromPort("Output PixelType"):
outPixelType = self.getInputFromPort("Output PixelType")
else:
outPixelType = inPixelType
#check for dimension
if self.hasInputFromPort("Dimension"):
dim = self.getInputFromPort("Dimension")
else:
dim = im.getDim()
#set up filter
inImgType = itk.Image[inPixelType._type, dim]
outImgType = itk.Image[outPixelType._type, dim]
self.filter_ = itk.IsolatedWatershedImageFilter[inImgType, outImgType].New(im.getImg())
if self.hasInputFromPort("Seed1"):
self.filter_.SetSeed1(self.getInputFromPort("Seed1").ind_)
if self.hasInputFromPort("Seed2"):
self.filter_.SetSeed2(self.getInputFromPort("Seed2").ind_)
if self.hasInputFromPort("ReplaceValue1"):
self.filter_.SetReplaceValue1(self.getInputFromPort("ReplaceValue1"))
if self.hasInputFromPort("ReplaceValue2"):
self.filter_.SetReplaceValue2(self.getInputFromPort("ReplaceValue2"))
if self.hasInputFromPort("Threshold"):
self.filter_.SetThreshold(self.getInputFromPort("Threshold"))
self.filter_.Update()
#setup output image
outIm = Image()
outIm.setImg(self.filter_.GetOutput())
outIm.setPixelType(outPixelType)
outIm.setDim(dim)
self.setResult("Output Image", outIm)
self.setResult("Output PixelType", outPixelType)
self.setResult("Filter", self)
@classmethod
def register(cls, reg, basic):
reg.add_module(cls, name="Isolated Watershed Image Filter", namespace=cls.my_namespace)
reg.add_input_port(cls, "Input Image", (Image, 'Input Image'))
reg.add_input_port(cls, "Input PixelType", (PixelType, 'Input PixelType'),True)
reg.add_input_port(cls, "Dimension", (basic.Integer, 'Dimension'),True)
reg.add_input_port(cls, "Seed1", (Index2D, 'Seed 1 Location'))
reg.add_input_port(cls, "Output PixelType", (PixelType, 'Output PixelType'), True)
reg.add_input_port(cls, "Threshold", (basic.Float, 'Threshold'), True)
reg.add_input_port(cls, "Seed2", (Index2D, 'Seed 2 Location'))
reg.add_input_port(cls, "ReplaceValue1", (basic.Float, 'Replacement Value 1'), True);
reg.add_input_port(cls, "ReplaceValue2", (basic.Float, 'Replacement Value 2'), True);
reg.add_output_port(cls, "Output Image", (Image, 'Output Image'))
reg.add_output_port(cls, "Output PixelType", (PixelType, 'Output PixelType'))
class ConnectedThresholdImageFilter(Module):
my_namespace="Filter|Segmentation"
def compute(self):
im = self.getInputFromPort("Input Image")
#check for input PixelType
if self.hasInputFromPort("Input PixelType"):
inPixelType = self.getInputFromPort("Input PixelType")
else:
inPixelType = im.getPixelType()
#check for output PixelType
if self.hasInputFromPort("Output PixelType"):
outPixelType = self.getInputFromPort("Output PixelType")
else:
outPixelType = inPixelType
#check for dimension
if self.hasInputFromPort("Dimension"):
dim = self.getInputFromPort("Dimension")
else:
dim = im.getDim()
if self.hasInputFromPort("Seed2D"):
seed = self.getInputFromPort("Seed2D")
else:
seed = self.getInputFromPort("Seed3D")
replace = self.getInputFromPort("Replace Value")
t_lower = self.getInputFromPort("Lower Value")
t_upper = self.getInputFromPort("Upper Value")
#setup filter
inImgType = itk.Image[inPixelType._type, dim]
outImgType = itk.Image[outPixelType._type, dim]
self.filter_ = itk.ConnectedThresholdImageFilter[inImgType,outImgType].New(im.getImg())
self.filter_.SetSeed(seed.ind_)
self.filter_.SetReplaceValue(replace)
self.filter_.SetLower(t_lower)
self.filter_.SetUpper(t_upper)
self.filter_.Update()
#setup output image
outIm = Image()
outIm.setImg(self.filter_.GetOutput())
outIm.setPixelType(outPixelType)
outIm.setDim(dim)
self.setResult("Output Image", outIm)
self.setResult("Output PixelType", outPixelType)
@classmethod
def register(cls, reg, basic):
reg.add_module(cls, name="Connected Threshold Image Filter", namespace=cls.my_namespace)
reg.add_input_port(cls, "Input Image", (Image, 'Input Image'))
reg.add_input_port(cls, "Input PixelType", (PixelType, 'Input PixelType'),True)
reg.add_input_port(cls, "Output PixelType", (PixelType, 'Output PixelType'), True)
reg.add_input_port(cls, "Dimension", (basic.Integer, 'Dimension'),True)
reg.add_input_port(cls, "Seed2D", (Index2D, 'Seed Point'))
reg.add_input_port(cls, "Seed3D", (Index3D, 'Seed Point'))
reg.add_input_port(cls, "Replace Value", (basic.Float, 'Replacement Value'))
reg.add_input_port(cls, "Upper Value", (basic.Float, 'Upper Threshold Value'))
reg.add_input_port(cls, "Lower Value", (basic.Float, 'Lower Threshold Value'))
reg.add_output_port(cls, "Output Image", (Image, 'Output Image'))
reg.add_output_port(cls, "Output PixelType", (PixelType, 'Output PixelType'))
class ConfidenceConnectedImageFilter(Module):
my_namespace="Filter|Segmentation"
def compute(self):
im = self.getInputFromPort("Input Image")
#check for input PixelType
if self.hasInputFromPort("Input PixelType"):
inPixelType = self.getInputFromPort("Input PixelType")
else:
inPixelType = im.getPixelType()
#check for output PixelType
if self.hasInputFromPort("Output PixelType"):
outPixelType = self.getInputFromPort("Output PixelType")
else:
outPixelType = inPixelType
#check for dimension
if self.hasInputFromPort("Dimension"):
dim = self.getInputFromPort("Dimension")
else:
dim = im.getDim()
if self.hasInputFromPort("Seed2D"):
seed = self.getInputFromPort("Seed2D")
else:
seed = self.getInputFromPort("Seed3D")
replace = self.getInputFromPort("Replace Value")
multiplier = self.getInputFromPort("Multiplier")
iterations = self.getInputFromPort("Iterations")
radius = self.getInputFromPort("Neighborhood Radius")
#setup filter
inImgType = itk.Image[inPixelType._type,dim]
outImgType = itk.Image[outPixelType._type,dim]
self.filter_ = itk.ConfidenceConnectedImageFilter[inImgType,outImgType].New(im.getImg())
self.filter_.SetReplaceValue(replace)
self.filter_.SetMultiplier(multiplier)
self.filter_.SetNumberOfIterations(iterations)
self.filter_.SetInitialNeighborhoodRadius(radius)
self.filter_.SetSeed(seed.ind_)
self.filter_.Update()
#setup output image
outIm = Image()
outIm.setImg(self.filter_.GetOutput())
outIm.setPixelType(outPixelType)
outIm.setDim(dim)
self.setResult("Output Image", outIm)
self.setResult("Output PixelType", outPixelType)
@classmethod
def register(cls, reg, basic):
reg.add_module(cls, name="Confidence Connected Image Filter", namespace=cls.my_namespace)
reg.add_input_port(cls, "Input Image", (Image, 'Input Image'))
reg.add_input_port(cls, "Input PixelType", (PixelType, 'Input PixelType'),True)
reg.add_input_port(cls, "Output PixelType", (PixelType, 'Output PixelType'), True)
reg.add_input_port(cls, "Dimension", (basic.Integer, 'Dimension'),True)
reg.add_input_port(cls, "Seed2D", (Index2D, 'Seed Point'))
reg.add_input_port(cls, "Seed3D", (Index3D, 'Seed Point'))
reg.add_input_port(cls, "Replace Value", (basic.Float, 'Replacement Value'))
reg.add_input_port(cls, "Multiplier", (basic.Float, 'Multiplier'))
reg.add_input_port(cls, "Iterations", (basic.Float, 'Iterations'))
reg.add_input_port(cls, "Neighborhood Radius", (basic.Float, 'Neighborhood Radius'))
reg.add_output_port(cls, "Output Image", (Image, 'Output Image'))
reg.add_output_port(cls, "Output PixelType", (PixelType, 'Output PixelType'))
class IsolatedConnectedImageFilter(Module):
my_namespace="Filter|Segmentation"
def compute(self):
im = self.getInputFromPort("Input Image")
#check for input PixelType
if self.hasInputFromPort("Input PixelType"):
inPixelType = self.getInputFromPort("Input PixelType")
else:
inPixelType = im.getPixelType()
#check for output PixelType
if self.hasInputFromPort("Output PixelType"):
outPixelType = self.getInputFromPort("Output PixelType")
else:
outPixelType = inPixelType
#check for dimension
if self.hasInputFromPort("Dimension"):
dim = self.getInputFromPort("Dimension")
else:
dim = im.getDim()
seed1 = self.getInputFromPort("Seed1")
seed2 = self.getInputFromPort("Seed2")
replace = self.getInputFromPort("Replace Value")
t_lower = self.getInputFromPort("Lower Value")
t_upper = self.getInputFromPort("Upper Value")
inImgType = itk.Image[inPixelType._type,dim]
outImgType = itk.Image[outPixelType._type,dim]
self.filter_ = itk.IsolatedConnectedImageFilter[inImgType,outImgType].New(im.getImg())
self.filter_.SetReplaceValue(replace)
self.filter_.SetLower(t_lower)
self.filter_.SetUpperValueLimit(t_upper)
self.filter_.SetSeed1(seed1.ind_)
self.filter_.SetSeed2(seed2.ind_)
self.filter_.Update()
#setup output image
outIm = Image()
outIm.setImg(self.filter_.GetOutput())
outIm.setPixelType(outPixelType)
outIm.setDim(dim)
self.setResult("Output Image", outIm)
self.setResult("Output PixelType", outPixelType)
@classmethod
def register(cls, reg, basic):
reg.add_module(cls, name="Isolated Connected Image Filter", namespace=cls.my_namespace)
reg.add_input_port(cls, "Input Image", (Image, 'Input Image'))
reg.add_input_port(cls, "Input PixelType", (PixelType, 'Input PixelType'),True)
reg.add_input_port(cls, "Output PixelType", (PixelType, 'Output PixelType'), True)
reg.add_input_port(cls, "Dimension", (basic.Integer, 'Dimension'),True)
reg.add_input_port(cls, "Seed1", (Index2D, 'Seed Point'))
reg.add_input_port(cls, "Seed2", (Index2D, 'Seed Point'))
reg.add_input_port(cls, "Replace Value", (basic.Integer, 'Replacement Value'))
reg.add_input_port(cls, "Upper Value", (basic.Integer, 'Upper Threshold Value'))
reg.add_input_port(cls, "Lower Value", (basic.Integer, 'Lower Threshold Value'))
reg.add_output_port(cls, "Output Image", (Image, 'Output Image'))
reg.add_output_port(cls, "Output PixelType", (PixelType, 'Output PixelType'))
|