How to use dicom-parser - 10 common examples

To help you get started, we’ve selected a few dicom-parser 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 FNNDSC / ami / src / parsers / parsers.dicom.js View on Github external
constructor(data, id) {
    super();

    this._id = id;

    this._arrayBuffer = data.buffer;

    let byteArray = new Uint8Array(this._arrayBuffer);

    // catch error
    // throw error if any!
    this._dataSet = null;

    try {
      this._dataSet = DicomParser.parseDicom(byteArray);
    } catch (e) {
      console.log(e);
      const error = new Error('parsers.dicom could not parse the file');
      throw error;
    }
  }
github FNNDSC / ami / src / parsers / parsers.dicom.js View on Github external
this._dataSet.elements.x7fe00010,
        frameIndex
      );
    }

    if (this.framesAreFragmented()) {
      // Basic Offset Table is empty
      return DicomParser.readEncapsulatedImageFrame(
        this._dataSet,
        this._dataSet.elements.x7fe00010,
        frameIndex,
        DicomParser.createJPEGBasicOffsetTable(this._dataSet, this._dataSet.elements.x7fe00010)
      );
    }

    return DicomParser.readEncapsulatedPixelDataFromFragments(
      this._dataSet,
      this._dataSet.elements.x7fe00010,
      frameIndex
    );
  }
github FNNDSC / ami / src / parsers / parsers.dicom.js View on Github external
const columns = this.columns();
    const rows = this.rows();
    const samplesPerPixel = this.samplesPerPixel(frameIndex);
    const pixelRepresentation = this.pixelRepresentation(frameIndex);

    // format data for the RLE decoder
    const imageFrame = {
      pixelRepresentation,
      bitsAllocated,
      planarConfiguration,
      columns,
      rows,
      samplesPerPixel,
    };

    const pixelData = DicomParser.readEncapsulatedPixelDataFromFragments(
      this._dataSet,
      this._dataSet.elements.x7fe00010,
      frameIndex
    );

    const decoded = RLEDecoder(imageFrame, pixelData);
    return decoded.pixelData;
  }
github FNNDSC / ami / src / parsers / parsers.dicom.js View on Github external
getEncapsulatedImageFrame(frameIndex) {
    if (
      this._dataSet.elements.x7fe00010 &&
      this._dataSet.elements.x7fe00010.basicOffsetTable.length
    ) {
      // Basic Offset Table is not empty
      return DicomParser.readEncapsulatedImageFrame(
        this._dataSet,
        this._dataSet.elements.x7fe00010,
        frameIndex
      );
    }

    if (this.framesAreFragmented()) {
      // Basic Offset Table is empty
      return DicomParser.readEncapsulatedImageFrame(
        this._dataSet,
        this._dataSet.elements.x7fe00010,
        frameIndex,
        DicomParser.createJPEGBasicOffsetTable(this._dataSet, this._dataSet.elements.x7fe00010)
      );
    }
github FNNDSC / ami / src / parsers / parsers.dicom.js View on Github external
getEncapsulatedImageFrame(frameIndex) {
    if (
      this._dataSet.elements.x7fe00010 &&
      this._dataSet.elements.x7fe00010.basicOffsetTable.length
    ) {
      // Basic Offset Table is not empty
      return DicomParser.readEncapsulatedImageFrame(
        this._dataSet,
        this._dataSet.elements.x7fe00010,
        frameIndex
      );
    }

    if (this.framesAreFragmented()) {
      // Basic Offset Table is empty
      return DicomParser.readEncapsulatedImageFrame(
        this._dataSet,
        this._dataSet.elements.x7fe00010,
        frameIndex,
        DicomParser.createJPEGBasicOffsetTable(this._dataSet, this._dataSet.elements.x7fe00010)
      );
    }

    return DicomParser.readEncapsulatedPixelDataFromFragments(
      this._dataSet,
      this._dataSet.elements.x7fe00010,
      frameIndex
    );
  }
github InsightSoftwareConsortium / itk-js / examples / Dicom / src / parseDicomFiles.js View on Github external
const parseFile = async (file) => {
    // Read
    const arrayBuffer = await PromiseFileReader.readAsArrayBuffer(file)

    // Parse
    const byteArray = new Uint8Array(arrayBuffer)
    const dicomMetaData = dicomParser.parseDicom(byteArray)

    // Add to patientDict
    const tag = DICOMPatient.primaryTag
    const patientId = dicomMetaData.string(DICOM_DICTIONARY[tag])
    var patient = patientDict[patientId]
    if (patient === undefined) {
      patient = new DICOMPatient()
      patientDict[patientId] = patient
    }
    patient.parseMetaData(dicomMetaData, file)
  }
github FNNDSC / ami / src / parsers / parsers.dicom.js View on Github external
) {
      // Basic Offset Table is not empty
      return DicomParser.readEncapsulatedImageFrame(
        this._dataSet,
        this._dataSet.elements.x7fe00010,
        frameIndex
      );
    }

    if (this.framesAreFragmented()) {
      // Basic Offset Table is empty
      return DicomParser.readEncapsulatedImageFrame(
        this._dataSet,
        this._dataSet.elements.x7fe00010,
        frameIndex,
        DicomParser.createJPEGBasicOffsetTable(this._dataSet, this._dataSet.elements.x7fe00010)
      );
    }

    return DicomParser.readEncapsulatedPixelDataFromFragments(
      this._dataSet,
      this._dataSet.elements.x7fe00010,
      frameIndex
    );
  }
github OHIF / ohif-core / src / lib / parsingUtils.js View on Github external
multiValue: function(data, tag, parser) {
    if (this.isValidDataSet(data) && tag in data.elements) {
      let element = data.elements[tag];
      if (element && element.length > 0) {
        let string = dicomParser.readFixedString(
          data.byteArray,
          element.dataOffset,
          element.length
        );
        if (typeof string === 'string' && string.length > 0) {
          if (typeof parser !== 'function') {
            parser = null;
          }

          return string.split('\\').map(function(value) {
            value = value.trim();
            return parser !== null ? parser(value) : value;
          });
        }
      }
    }
github OHIF / Viewers / extensions / dicom-pdf / src / DicomPDFViewport.js View on Github external
parseByteArray = byteArray => {
    const options = {
      untilTag: '',
    };

    let dataSet;

    try {
      dataSet = dicomParser.parseDicom(byteArray, options);
    } catch (error) {
      this.setState({
        error,
      });
    }

    return dataSet;
  };
github OHIF / ohif-core / src / lib / parsingUtils.js View on Github external
isValidDataSet: function(data) {
    return data instanceof dicomParser.DataSet;
  },