Exemplo n.º 1
0
    def execute(self, inputs=(1, 1), update=0, last=0):
        """
		Execute filter in input image and return output image
		"""
        if not lib.ProcessingFilter.ProcessingFilter.execute(self, inputs):
            return None

        self.eventDesc = "Calculating FFT"
        inputImage = self.getInput(1)

        # Convert image to float
        origType = inputImage.GetScalarType()
        castFloat = vtk.vtkImageCast()
        castFloat.SetOutputScalarTypeToFloat()
        self.filter = vtk.vtkImageFFT()
        #magnitude = vtk.vtkImageMagnitude()
        #fourierCenter = vtk.vtkImageFourierCenter()
        #logarithmic = vtk.vtkImageLogarithmicScale()
        #logarithmic.SetConstant(15)

        castFloat.SetInput(inputImage)
        self.filter.SetInputConnection(castFloat.GetOutputPort())
        #magnitude.SetInputConnection(self.filter.GetOutputPort())
        #fourierCenter.SetInputConnection(magnitude.GetOutputPort())
        #logarithmic.SetInputConnection(fourierCenter.GetOutputPort())
        #outputImage = logarithmic.GetOutput()
        outputImage = self.filter.GetOutput()

        if update:
            outputImage.Update()

        return outputImage
	def execute(self, inputs = (1,1), update = 0, last = 0):
		"""
		Execute filter in input image and return output image
		"""
		if not lib.ProcessingFilter.ProcessingFilter.execute(self,inputs):
			return None

		self.eventDesc = "Calculating FFT"
		inputImage = self.getInput(1)

		# Convert image to float
		origType = inputImage.GetScalarType()
		castFloat = vtk.vtkImageCast()
		castFloat.SetOutputScalarTypeToFloat()
		self.filter = vtk.vtkImageFFT()
		#magnitude = vtk.vtkImageMagnitude()
		#fourierCenter = vtk.vtkImageFourierCenter()
		#logarithmic = vtk.vtkImageLogarithmicScale()
		#logarithmic.SetConstant(15)

		castFloat.SetInput(inputImage)
		self.filter.SetInputConnection(castFloat.GetOutputPort())
		#magnitude.SetInputConnection(self.filter.GetOutputPort())
		#fourierCenter.SetInputConnection(magnitude.GetOutputPort())
		#logarithmic.SetInputConnection(fourierCenter.GetOutputPort())
		#outputImage = logarithmic.GetOutput()
		outputImage = self.filter.GetOutput()
		
		if update:
			outputImage.Update()

		return outputImage
Exemplo n.º 3
0
 def __init__(self, module_manager):
     SimpleVTKClassModuleBase.__init__(
         self, module_manager,
         vtk.vtkImageFFT(), 'Processing.',
         ('vtkImageData',), ('vtkImageData',),
         replaceDoc=True,
         inputFunctions=None, outputFunctions=None)
Exemplo n.º 4
0
 def __init__(self, module_manager):
     SimpleVTKClassModuleBase.__init__(self,
                                       module_manager,
                                       vtk.vtkImageFFT(),
                                       'Processing.', ('vtkImageData', ),
                                       ('vtkImageData', ),
                                       replaceDoc=True,
                                       inputFunctions=None,
                                       outputFunctions=None)
Exemplo n.º 5
0
    def fft(self, mode='magnitude', logscale=12, center=True):
        """Fast Fourier transform of a picture.

        :param float logscale: if non-zero, take the logarithm of the
            intensity and scale it by this factor.

        :param str mode: either [magnitude, real, imaginary, complex], compute the
            point array data accordingly.
        :param bool center: shift constant zero-frequency to the center of the image for display.
            (FFT converts spatial images into frequency space, but puts the zero frequency at the origin)
        """
        ffti = vtk.vtkImageFFT()
        ffti.SetInputData(self._data)
        ffti.Update()

        if 'mag' in mode:
            mag = vtk.vtkImageMagnitude()
            mag.SetInputData(ffti.GetOutput())
            mag.Update()
            out = mag.GetOutput()
        elif 'real' in mode:
            extractRealFilter = vtk.vtkImageExtractComponents()
            extractRealFilter.SetInputData(ffti.GetOutput())
            extractRealFilter.SetComponents(0)
            extractRealFilter.Update()
            out = extractRealFilter.GetOutput()
        elif 'imaginary' in mode:
            extractImgFilter = vtk.vtkImageExtractComponents()
            extractImgFilter.SetInputData(ffti.GetOutput())
            extractImgFilter.SetComponents(1)
            extractImgFilter.Update()
            out = extractImgFilter.GetOutput()
        elif 'complex' in mode:
            out = ffti.GetOutput()
        else:
            colors.printc("Error in fft(): unknown mode", mode)
            raise RuntimeError()

        if center:
            center = vtk.vtkImageFourierCenter()
            center.SetInputData(out)
            center.Update()
            out = center.GetOutput()

        if 'complex' not in mode:
            if logscale:
                ils = vtk.vtkImageLogarithmicScale()
                ils.SetInputData(out)
                ils.SetConstant(logscale)
                ils.Update()
                out = ils.GetOutput()

        return Picture(out)
Exemplo n.º 6
0
    def filterpass(self, lowcutoff=None, highcutoff=None, order=3):
        """
        Low-pass and high-pass filtering become trivial in the frequency domain.
        A portion of the pixels/voxels are simply masked or attenuated.
        This function applies a high pass Butterworth filter that attenuates the
        frequency domain image with the function

        |G_Of_Omega|

        The gradual attenuation of the filter is important.
        A simple high-pass filter would simply mask a set of pixels in the frequency domain,
        but the abrupt transition would cause a ringing effect in the spatial domain.

        :param list lowcutoff:  the cutoff frequencies
        :param list highcutoff: the cutoff frequencies
        :param int order: order determines sharpness of the cutoff curve
        """
        #https://lorensen.github.io/VTKExamples/site/Cxx/ImageProcessing/IdealHighPass
        fft = vtk.vtkImageFFT()
        fft.SetInputData(self._data)
        fft.Update()
        out = fft.GetOutput()

        if highcutoff:
            butterworthLowPass = vtk.vtkImageButterworthLowPass()
            butterworthLowPass.SetInputData(out)
            butterworthLowPass.SetCutOff(highcutoff)
            butterworthLowPass.SetOrder(order)
            butterworthLowPass.Update()
            out = butterworthLowPass.GetOutput()

        if lowcutoff:
            butterworthHighPass = vtk.vtkImageButterworthHighPass()
            butterworthHighPass.SetInputData(out)
            butterworthHighPass.SetCutOff(lowcutoff)
            butterworthHighPass.SetOrder(order)
            butterworthHighPass.Update()
            out = butterworthHighPass.GetOutput()

        butterworthRfft = vtk.vtkImageRFFT()
        butterworthRfft.SetInputData(out)
        butterworthRfft.Update()

        butterworthReal = vtk.vtkImageExtractComponents()
        butterworthReal.SetInputData(butterworthRfft.GetOutput())
        butterworthReal.SetComponents(0)
        butterworthReal.Update()

        caster = vtk.vtkImageCast()
        caster. SetOutputScalarTypeToUnsignedChar()
        caster.SetInputData(butterworthReal.GetOutput())
        caster.Update()
        return self._update(caster.GetOutput())
Exemplo n.º 7
0
    def Execute(self):

        if not self.Image:
            self.PrintError('Error: no Image.')

        fft = vtk.vtkImageFFT()
        fft.SetInput(self.Image)
        fft.SetDimensionality(self.KSpaceDimensionality)
        fft.Update()

        origin = self.Image.GetOrigin()
        spacing = self.Image.GetSpacing()
        dimensions = self.Image.GetDimensions()
        kspacing = [1.0/(dimensions[0]*spacing[0]),1.0/(dimensions[1]*spacing[1]),1.0/(dimensions[2]*spacing[2])]
  
        imageInformation = vtk.vtkImageChangeInformation()
        imageInformation.SetInput(fft.GetOutput())
        imageInformation.SetOutputSpacing(kspacing)
        imageInformation.SetOutputOrigin(origin)
        imageInformation.Update()
        
        self.KSpace = imageInformation.GetOutput()
Exemplo n.º 8
0
#!/usr/bin/env python
import vtk
from vtk.test import Testing
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()

# This script shows the result of an ideal highpass filter in  spatial domain
# Image pipeline
createReader = vtk.vtkImageReader2Factory()
reader = createReader.CreateImageReader2("" + str(VTK_DATA_ROOT) + "/Data/fullhead15.png")
reader.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/fullhead15.png")
fft = vtk.vtkImageFFT()
fft.SetInputConnection(reader.GetOutputPort())
highPass = vtk.vtkImageIdealHighPass()
highPass.SetInputConnection(fft.GetOutputPort())
highPass.SetXCutOff(0.1)
highPass.SetYCutOff(0.1)
highPass.ReleaseDataFlagOff()
rfft = vtk.vtkImageRFFT()
rfft.SetInputConnection(highPass.GetOutputPort())
real = vtk.vtkImageExtractComponents()
real.SetInputConnection(rfft.GetOutputPort())
real.SetComponents(0)
viewer = vtk.vtkImageViewer()
viewer.SetInputConnection(real.GetOutputPort())
viewer.SetColorWindow(500)
viewer.SetColorLevel(0)
viewer.Render()
reader.UnRegister(viewer) # not needed in python
# --- end of script --
Exemplo n.º 9
0
#!/usr/bin/env python
import vtk
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()

# This script shows the result of an ideal lowpass filter in frequency space.
# Image pipeline
reader = vtk.vtkPNGReader()
reader.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/fullhead15.png")
fft = vtk.vtkImageFFT()
fft.SetDimensionality(2)
fft.SetInputConnection(reader.GetOutputPort())
#fft DebugOn
lowPass = vtk.vtkImageButterworthLowPass()
lowPass.SetInputConnection(fft.GetOutputPort())
lowPass.SetOrder(2)
lowPass.SetXCutOff(0.2)
lowPass.SetYCutOff(0.1)
lowPass.ReleaseDataFlagOff()
#lowPass DebugOn
viewer = vtk.vtkImageViewer()
viewer.SetInputConnection(lowPass.GetOutputPort())
viewer.SetColorWindow(10000)
viewer.SetColorLevel(5000)
#viewer DebugOn
viewer.Render()
# --- end of script --
Exemplo n.º 10
0
def main():
    colors = vtk.vtkNamedColors()

    fileName = get_program_parameters()

    # Read the image.
    readerFactory = vtk.vtkImageReader2Factory()
    reader = readerFactory.CreateImageReader2(fileName)
    reader.SetFileName(fileName)
    reader.Update()

    fft = vtk.vtkImageFFT()
    fft.SetInputConnection(reader.GetOutputPort())

    idealHighPass = vtk.vtkImageIdealHighPass()
    idealHighPass.SetInputConnection(fft.GetOutputPort())
    idealHighPass.SetXCutOff(0.1)
    idealHighPass.SetYCutOff(0.1)

    idealRfft = vtk.vtkImageRFFT()
    idealRfft.SetInputConnection(idealHighPass.GetOutputPort())

    idealReal = vtk.vtkImageExtractComponents()
    idealReal.SetInputConnection(idealRfft.GetOutputPort())
    idealReal.SetComponents(0)

    butterworthHighPass = vtk.vtkImageButterworthHighPass()
    butterworthHighPass.SetInputConnection(fft.GetOutputPort())
    butterworthHighPass.SetXCutOff(0.1)
    butterworthHighPass.SetYCutOff(0.1)

    butterworthRfft = vtk.vtkImageRFFT()
    butterworthRfft.SetInputConnection(butterworthHighPass.GetOutputPort())

    butterworthReal = vtk.vtkImageExtractComponents()
    butterworthReal.SetInputConnection(butterworthRfft.GetOutputPort())
    butterworthReal.SetComponents(0)

    # Create the actors.
    idealColor = vtk.vtkImageMapToWindowLevelColors()
    idealColor.SetWindow(500)
    idealColor.SetLevel(0)
    idealColor.SetInputConnection(idealReal.GetOutputPort())

    idealActor = vtk.vtkImageActor()
    idealActor.GetMapper().SetInputConnection(idealColor.GetOutputPort())
    idealActor.GetProperty().SetInterpolationTypeToNearest()

    butterworthColor = vtk.vtkImageMapToWindowLevelColors()
    butterworthColor.SetWindow(500)
    butterworthColor.SetLevel(0)
    butterworthColor.SetInputConnection(butterworthReal.GetOutputPort())

    butterworthActor = vtk.vtkImageActor()
    butterworthActor.GetMapper().SetInputConnection(butterworthColor.GetOutputPort())
    butterworthActor.GetProperty().SetInterpolationTypeToNearest()

    # Setup the renderers.
    idealRenderer = vtk.vtkRenderer()
    idealRenderer.SetViewport(0.0, 0.0, 0.5, 1.0)
    idealRenderer.AddActor(idealActor)
    idealRenderer.ResetCamera()
    idealRenderer.SetBackground(colors.GetColor3d("SlateGray"))

    butterworthRenderer = vtk.vtkRenderer()
    butterworthRenderer.SetViewport(0.5, 0.0, 1.0, 1.0)
    butterworthRenderer.AddActor(butterworthActor)
    butterworthRenderer.SetActiveCamera(idealRenderer.GetActiveCamera())
    butterworthRenderer.SetBackground(colors.GetColor3d("LightSlateGray"))

    renderWindow = vtk.vtkRenderWindow()
    renderWindow.SetSize(600, 300)
    renderWindow.SetWindowName('IdealHighPass')
    renderWindow.AddRenderer(idealRenderer)
    renderWindow.AddRenderer(butterworthRenderer)

    renderWindowInteractor = vtk.vtkRenderWindowInteractor()
    style = vtk.vtkInteractorStyleImage()

    renderWindowInteractor.SetInteractorStyle(style)

    renderWindowInteractor.SetRenderWindow(renderWindow)
    idealRenderer.GetActiveCamera().Dolly(1.4)
    idealRenderer.ResetCameraClippingRange()
    renderWindowInteractor.Initialize()

    renderWindowInteractor.Start()
Exemplo n.º 11
0
# Performs a correlation in frequency domain.
s1 = vtk.vtkImageCanvasSource2D()
s1.SetScalarTypeToFloat()
s1.SetExtent(0, 255, 0, 255, 0, 0)
s1.SetDrawColor(0)
s1.FillBox(0, 255, 0, 255)
s1.SetDrawColor(2.0)
s1.FillTriangle(10, 100, 190, 150, 40, 250)
s2 = vtk.vtkImageCanvasSource2D()
s2.SetScalarTypeToFloat()
s2.SetExtent(0, 31, 0, 31, 0, 0)
s2.SetDrawColor(0.0)
s2.FillBox(0, 31, 0, 31)
s2.SetDrawColor(2.0)
s2.FillTriangle(10, 1, 25, 10, 1, 5)
fft1 = vtk.vtkImageFFT()
fft1.SetDimensionality(2)
fft1.SetInputConnection(s1.GetOutputPort())
fft1.ReleaseDataFlagOff()
fft1.Update()
# Pad kernel out to same size as image.
pad2 = vtk.vtkImageConstantPad()
pad2.SetInputConnection(s2.GetOutputPort())
pad2.SetOutputWholeExtent(0, 255, 0, 255, 0, 0)
fft2 = vtk.vtkImageFFT()
fft2.SetDimensionality(2)
fft2.SetInputConnection(pad2.GetOutputPort())
fft2.ReleaseDataFlagOff()
fft2.Update()
# conjugate is necessary for correlation (not convolution)
conj = vtk.vtkImageMathematics()
Exemplo n.º 12
0
def main():
    colors = vtk.vtkNamedColors()

    fileName = get_program_parameters()

    # Read the image.
    readerFactory = vtk.vtkImageReader2Factory()
    reader = readerFactory.CreateImageReader2(fileName)
    reader.SetFileName(fileName)
    reader.Update()

    fft = vtk.vtkImageFFT()
    fft.SetInputConnection(reader.GetOutputPort())

    mag = vtk.vtkImageMagnitude()
    mag.SetInputConnection(fft.GetOutputPort())

    center = vtk.vtkImageFourierCenter()
    center.SetInputConnection(mag.GetOutputPort())

    compress = vtk.vtkImageLogarithmicScale()
    compress.SetInputConnection(center.GetOutputPort())
    compress.SetConstant(15)
    compress.Update()

    # Create the actors.
    originalActor = vtk.vtkImageActor()
    originalActor.GetMapper().SetInputConnection(reader.GetOutputPort())
    originalActor.GetProperty().SetInterpolationTypeToNearest()

    compressedActor = vtk.vtkImageActor()
    compressedActor.GetMapper().SetInputConnection(compress.GetOutputPort())
    compressedActor.GetProperty().SetInterpolationTypeToNearest()
    CreateImageActor(compressedActor, 160, 120)

    # Define the viewport ranges.
    # (xmin, ymin, xmax, ymax)
    originalViewport = [0.0, 0.0, 0.5, 1.0]
    compressedViewport = [0.5, 0.0, 1.0, 1.0]

    # Setup the renderers.
    originalRenderer = vtk.vtkRenderer()
    originalRenderer.SetViewport(originalViewport)
    originalRenderer.AddActor(originalActor)
    originalRenderer.ResetCamera()
    originalRenderer.SetBackground(colors.GetColor3d("SlateGray"))

    compressedRenderer = vtk.vtkRenderer()
    compressedRenderer.SetViewport(compressedViewport)
    compressedRenderer.AddActor(compressedActor)
    compressedRenderer.ResetCamera()
    compressedRenderer.SetBackground(colors.GetColor3d("LightSlateGray"))

    renderWindow = vtk.vtkRenderWindow()
    renderWindow.SetSize(600, 300)
    renderWindow.SetWindowName('VTKSpectrum')
    renderWindow.AddRenderer(originalRenderer)
    renderWindow.AddRenderer(compressedRenderer)

    renderWindowInteractor = vtk.vtkRenderWindowInteractor()
    style = vtk.vtkInteractorStyleImage()

    renderWindowInteractor.SetInteractorStyle(style)

    renderWindowInteractor.SetRenderWindow(renderWindow)
    renderWindowInteractor.Initialize()

    renderWindowInteractor.Start()
# Performs a correlation in frequency domain.
s1 = vtk.vtkImageCanvasSource2D()
s1.SetScalarTypeToFloat()
s1.SetExtent(0,255,0,255,0,0)
s1.SetDrawColor(0)
s1.FillBox(0,255,0,255)
s1.SetDrawColor(2.0)
s1.FillTriangle(10,100,190,150,40,250)
s2 = vtk.vtkImageCanvasSource2D()
s2.SetScalarTypeToFloat()
s2.SetExtent(0,31,0,31,0,0)
s2.SetDrawColor(0.0)
s2.FillBox(0,31,0,31)
s2.SetDrawColor(2.0)
s2.FillTriangle(10,1,25,10,1,5)
fft1 = vtk.vtkImageFFT()
fft1.SetDimensionality(2)
fft1.SetInputConnection(s1.GetOutputPort())
fft1.ReleaseDataFlagOff()
fft1.Update()
# Pad kernel out to same size as image.
pad2 = vtk.vtkImageConstantPad()
pad2.SetInputConnection(s2.GetOutputPort())
pad2.SetOutputWholeExtent(0,255,0,255,0,0)
fft2 = vtk.vtkImageFFT()
fft2.SetDimensionality(2)
fft2.SetInputConnection(pad2.GetOutputPort())
fft2.ReleaseDataFlagOff()
fft2.Update()
# conjugate is necessary for correlation (not convolution)
conj = vtk.vtkImageMathematics()