How to use itk - 10 common examples

To help you get started, we’ve selected a few itk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github InsightSoftwareConsortium / itk-js / examples / Dicom / src / index.js View on Github external
setupDicomForm(patientDict, async (files) => {
    outputTextArea.textContent = "Loading..."

    // Read DICOM serie
    const { image, webWorker } = await readImageDICOMFileSeries(null, files)
    webWorker.terminate()

    // Display
    function replacer (key, value) {
      if (!!value && value.byteLength !== undefined) {
        return String(value.slice(0, 6)) + '...'
      }
      return value
    }
    outputTextArea.textContent = JSON.stringify(image, replacer, 4)
  })
})
github InsightSoftwareConsortium / itkwidgets / js / lib / viewer.js View on Github external
}
  const numberOfBytes = pixelCount * image.imageType.components * componentSize
  const pipelinePath = 'ZstdDecompress'
  const args = ['input.bin', 'output.bin', String(numberOfBytes)]
  const desiredOutputs = [
    { path: 'output.bin', type: IOTypes.Binary }
  ]
  const inputs = [
    { path: 'input.bin', type: IOTypes.Binary, data: byteArray }
  ]
  console.log(`input MB: ${byteArray.length / 1000 / 1000}`)
  console.log(`output MB: ${numberOfBytes / 1000 / 1000 }`)
  const compressionAmount = byteArray.length / numberOfBytes
  console.log(`compression amount: ${compressionAmount}`)
  const t0 = performance.now()
  return runPipelineBrowser(null, pipelinePath, args, desiredOutputs, inputs)
    .then(function ({stdout, stderr, outputs, webWorker}) {
      webWorker.terminate()
      const t1 = performance.now();
      const duration = Number(t1 - t0).toFixed(1).toString()
      console.log("decompression took " + duration + " milliseconds.")

      switch (image.imageType.componentType) {
        case IntTypes.Int8:
          image.data = new Int8Array(outputs[0].data.buffer)
          break
        case IntTypes.UInt8:
          image.data = outputs[0].data
          break
        case IntTypes.Int16:
          image.data = new Int16Array(outputs[0].data.buffer)
          break
github InsightSoftwareConsortium / itkwidgets / js / lib / viewer.js View on Github external
const elementSize = DataTypeByteSize[polyData[prop].dataType]
  const numberOfBytes = polyData[prop].size * elementSize
  const pipelinePath = 'ZstdDecompress'
  const args = ['input.bin', 'output.bin', String(numberOfBytes)]
  const desiredOutputs = [
    { path: 'output.bin', type: IOTypes.Binary }
  ]
  const inputs = [
    { path: 'input.bin', type: IOTypes.Binary, data: byteArray }
  ]
  console.log(`${prop} input MB: ${byteArray.length / 1000 / 1000}`)
  console.log(`${prop} output MB: ${numberOfBytes / 1000 / 1000 }`)
  const compressionAmount = byteArray.length / numberOfBytes
  console.log(`${prop} compression amount: ${compressionAmount}`)
  const t0 = performance.now()
  return runPipelineBrowser(null, pipelinePath, args, desiredOutputs, inputs)
    .then(function ({stdout, stderr, outputs, webWorker}) {
      webWorker.terminate()
      const t1 = performance.now();
      const duration = Number(t1 - t0).toFixed(1).toString()
      console.log(`${prop} decompression took ${duration} milliseconds.`)
      polyData[prop]['values'] = new window[polyData[prop].dataType](outputs[0].data.buffer)

      return polyData
    })
}
github Kitware / itk-vtk-viewer / src / processFiles.js View on Github external
return readMeshFile(null, file).then(({ mesh: itkMesh, webWorker }) => {
            const read1 = performance.now();
            const duration = Number(read1 - read0).toFixed(1).toString()
            console.log("Mesh reading took " + duration + " milliseconds.")
            webWorker.terminate()
            const pipelinePath = 'MeshToPolyData'
            const args = ['mesh.json', 'polyData.json']
            const desiredOutputs = [
              { path: args[1], type: IOTypes.vtkPolyData }
            ]
            const inputs = [
              { path: args[0], type: IOTypes.Mesh, data: itkMesh }
            ]
            is3D = itkMesh.meshType.dimension === 3
            convert0 = performance.now()
            return runPipelineBrowser(null, pipelinePath, args, desiredOutputs, inputs)
          }).then(function ({ outputs, webWorker }) {
            const convert1 = performance.now();
github InsightSoftwareConsortium / itkwidgets / js / lib / viewer.js View on Github external
function decompressDataValue(polyData, prop) {
  if (!polyData.hasOwnProperty(prop)) {
    return Promise.resolve(polyData)
  }
  const byteArray = new Uint8Array(polyData[prop].compressedValues.buffer)
  const elementSize = DataTypeByteSize[polyData[prop].dataType]
  const numberOfBytes = polyData[prop].size * elementSize
  const pipelinePath = 'ZstdDecompress'
  const args = ['input.bin', 'output.bin', String(numberOfBytes)]
  const desiredOutputs = [
    { path: 'output.bin', type: IOTypes.Binary }
  ]
  const inputs = [
    { path: 'input.bin', type: IOTypes.Binary, data: byteArray }
  ]
  console.log(`${prop} input MB: ${byteArray.length / 1000 / 1000}`)
  console.log(`${prop} output MB: ${numberOfBytes / 1000 / 1000 }`)
  const compressionAmount = byteArray.length / numberOfBytes
  console.log(`${prop} compression amount: ${compressionAmount}`)
  const t0 = performance.now()
  return runPipelineBrowser(null, pipelinePath, args, desiredOutputs, inputs)
    .then(function ({stdout, stderr, outputs, webWorker}) {
      webWorker.terminate()
      const t1 = performance.now();
      const duration = Number(t1 - t0).toFixed(1).toString()
      console.log(`${prop} decompression took ${duration} milliseconds.`)
      polyData[prop]['values'] = new window[polyData[prop].dataType](outputs[0].data.buffer)

      return polyData
    })
github InsightSoftwareConsortium / itkwidgets / js / lib / viewer.js View on Github external
function decompressDataValue(polyData, prop) {
  if (!polyData.hasOwnProperty(prop)) {
    return Promise.resolve(polyData)
  }
  const byteArray = new Uint8Array(polyData[prop].compressedValues.buffer)
  const elementSize = DataTypeByteSize[polyData[prop].dataType]
  const numberOfBytes = polyData[prop].size * elementSize
  const pipelinePath = 'ZstdDecompress'
  const args = ['input.bin', 'output.bin', String(numberOfBytes)]
  const desiredOutputs = [
    { path: 'output.bin', type: IOTypes.Binary }
  ]
  const inputs = [
    { path: 'input.bin', type: IOTypes.Binary, data: byteArray }
  ]
  console.log(`${prop} input MB: ${byteArray.length / 1000 / 1000}`)
  console.log(`${prop} output MB: ${numberOfBytes / 1000 / 1000 }`)
  const compressionAmount = byteArray.length / numberOfBytes
  console.log(`${prop} compression amount: ${compressionAmount}`)
  const t0 = performance.now()
  return runPipelineBrowser(null, pipelinePath, args, desiredOutputs, inputs)
    .then(function ({stdout, stderr, outputs, webWorker}) {
      webWorker.terminate()
      const t1 = performance.now();
      const duration = Number(t1 - t0).toFixed(1).toString()
      console.log(`${prop} decompression took ${duration} milliseconds.`)
      polyData[prop]['values'] = new window[polyData[prop].dataType](outputs[0].data.buffer)
github InsightSoftwareConsortium / itkwidgets / js / lib / viewer.js View on Github external
case IntTypes.UInt16:
          image.data = new Uint16Array(outputs[0].data.buffer)
          break
        case IntTypes.Int32:
          image.data = new Int32Array(outputs[0].data.buffer)
          break
        case IntTypes.UInt32:
          image.data = new Uint32Array(outputs[0].data.buffer)
          break
        case IntTypes.Int64:
          image.data = new BigUint64Array(outputs[0].data.buffer)
          break
        case IntTypes.UInt64:
          image.data = new BigUint64Array(outputs[0].data.buffer)
          break
        case FloatTypes.Float32:
          image.data = new Float32Array(outputs[0].data.buffer)
          break
        case FloatTypes.Float64:
          image.data = new Float64Array(outputs[0].data.buffer)
          break
        default:
          console.error('Unexpected component type: ' + image.imageType.componentType)
      }
      return image
    })
}
github InsightSoftwareConsortium / itkwidgets / js / lib / viewer.js View on Github external
case IntTypes.Int32:
      componentSize = 4
      break
    case IntTypes.UInt32:
      componentSize = 4
      break
    case IntTypes.Int64:
      componentSize = 8
      break
    case IntTypes.UInt64:
      componentSize = 8
      break
    case FloatTypes.Float32:
      componentSize = 4
      break
    case FloatTypes.Float64:
      componentSize = 8
      break
    default:
      console.error('Unexpected component type: ' + image.imageType.componentType)
  }
  const numberOfBytes = pixelCount * image.imageType.components * componentSize
  const pipelinePath = 'ZstdDecompress'
  const args = ['input.bin', 'output.bin', String(numberOfBytes)]
  const desiredOutputs = [
    { path: 'output.bin', type: IOTypes.Binary }
  ]
  const inputs = [
    { path: 'input.bin', type: IOTypes.Binary, data: byteArray }
  ]
  console.log(`input MB: ${byteArray.length / 1000 / 1000}`)
  console.log(`output MB: ${numberOfBytes / 1000 / 1000 }`)
github Kitware / itk-vtk-viewer / src / processFiles.js View on Github external
return readMeshFile(null, file).then(({ mesh: itkMesh, webWorker }) => {
            const read1 = performance.now();
            const duration = Number(read1 - read0).toFixed(1).toString()
            console.log("Mesh reading took " + duration + " milliseconds.")
            webWorker.terminate()
            const pipelinePath = 'MeshToPolyData'
            const args = ['mesh.json', 'polyData.json']
            const desiredOutputs = [
              { path: args[1], type: IOTypes.vtkPolyData }
            ]
            const inputs = [
              { path: args[0], type: IOTypes.Mesh, data: itkMesh }
            ]
            is3D = itkMesh.meshType.dimension === 3
            convert0 = performance.now()
            return runPipelineBrowser(null, pipelinePath, args, desiredOutputs, inputs)
          }).then(function ({ outputs, webWorker }) {
            const convert1 = performance.now();
github Kitware / itk-vtk-viewer / src / processFiles.js View on Github external
return readMeshFile(null, file).then(({ mesh: itkMesh, webWorker }) => {
            const read1 = performance.now();
            const duration = Number(read1 - read0).toFixed(1).toString()
            console.log("Mesh reading took " + duration + " milliseconds.")
            webWorker.terminate()
            const pipelinePath = 'MeshToPolyData'
            const args = ['mesh.json', 'polyData.json']
            const desiredOutputs = [
              { path: args[1], type: IOTypes.vtkPolyData }
            ]
            const inputs = [
              { path: args[0], type: IOTypes.Mesh, data: itkMesh }
            ]
            is3D = itkMesh.meshType.dimension === 3
            convert0 = performance.now()
            return runPipelineBrowser(null, pipelinePath, args, desiredOutputs, inputs)
          }).then(function ({ outputs, webWorker }) {
            const convert1 = performance.now();