def getMIP(imageData, color): """ A function that will take a volume and do a simple maximum intensity projection that will be converted to a wxBitmap """ maxval = imageData.GetScalarRange()[1] imageData.SetUpdateExtent(imageData.GetWholeExtent()) if maxval > 255: shiftscale = vtk.vtkImageShiftScale() shiftscale.SetInputConnection(imageData.GetProducerPort()) shiftscale.SetScale(255.0 / maxval) shiftscale.SetOutputScalarTypeToUnsignedChar() imageData = shiftscale.GetOutput() mip = vtkbxd.vtkImageSimpleMIP() mip.SetInputConnection(imageData.GetProducerPort()) if color == None: output = optimize.execute_limited(mip) return output if mip.GetOutput().GetNumberOfScalarComponents() == 1: ctf = getColorTransferFunction(color) maptocolor = vtk.vtkImageMapToColors() maptocolor.SetInputConnection(mip.GetOutputPort()) maptocolor.SetLookupTable(ctf) maptocolor.SetOutputFormatToRGB() imagedata = optimize.execute_limited(maptocolor) else: imagedata = output = optimize.execute_limited(mip) return imagedata
def vtkZoomImage(image, zoomInFactor): """ Zoom a volume """ zoomOutFactor = 1.0 / zoomInFactor reslice = vtk.vtkImageReslice() reslice.SetInputConnection(image.GetProducerPort()) spacing = image.GetSpacing() extent = image.GetExtent() origin = image.GetOrigin() extent = (extent[0], extent[1] / zoomOutFactor, extent[2], extent[3] / zoomOutFactor, extent[4], extent[5]) spacing = (spacing[0] * zoomOutFactor, spacing[1] * zoomOutFactor, spacing[2]) reslice.SetOutputSpacing(spacing) reslice.SetOutputExtent(extent) reslice.SetOutputOrigin(origin) # These interpolation settings were found to have the # best effect: # If we zoom out, no interpolation if zoomOutFactor > 1: reslice.InterpolateOff() else: # If we zoom in, use cubic interpolation reslice.SetInterpolationModeToCubic() reslice.InterpolateOn() data = optimize.execute_limited(reslice) data.Update() return data