npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

rt-convert-js

v0.1.1

Published

Convert between DICOM RT Structure Sets and DICOM Segmentation, with every lossy step recorded in provenance. Built on rt-geometry-js, rtstruct-js, and dicom-seg-js.

Readme

rt-convert-js

Convert between DICOM RT Structure Sets and DICOM Segmentation, built on rt-geometry-js, rtstruct-js, and dicom-seg-js. Part of the DICOM imaging toolkit.

Status: published — rt-convert-js 0.1.0 on npm. Both directions are implemented and round-trip-validated on real TCIA data — rtstructToSeg (RTSTRUCT ROI → BINARY SEG, voxel-for-voxel identical to the loaded ROI mask) and segToRtstruct (BINARY SEG straight through, FRACTIONAL SEG cut at a required threshold; the mask → contour step's fidelity is measured per conversion). See VALIDATION.md.

The two directions are not symmetric, and neither is lossless in general:

  • RTSTRUCT → SEG is a voxel copy. RTStruct.load already rasterized the contours onto a grid; this writes exactly those voxels. No information is lost here (it was lost, if at all, at rasterization time).
  • SEG → RTSTRUCT traces a mask to polygon contours (a vectorization), and — for a FRACTIONAL SEG — first cuts the probability/occupancy field to a binary mask at a threshold the caller must choose. RTSTRUCT cannot store a per-voxel value.

Every conversion returns { bytes, provenance }. provenance.lossySteps lists each step that does not round-trip, with the numbers to audit it. See docs/CONVERSION.md.

Install

npm install rt-convert-js rt-geometry-js rtstruct-js dicom-seg-js

All three toolkit packages are peer dependencies.

Use

import { RTStruct } from "rtstruct-js";
import { rtstructToSeg } from "rt-convert-js";

const rt = await RTStruct.load({ rtstruct: rtssBytes, geometry: ctGeometry });
const { bytes, provenance } = rtstructToSeg(rt, "Kidney", {
  category: { value: "T-D0050", scheme: "SRT", meaning: "Anatomical Structure" },
  propertyType: { value: "T-71000", scheme: "SRT", meaning: "Kidney" },
});

provenance.lossySteps; // []  — this direction is a voxel copy
import { readSeg } from "dicom-seg-js";
import { segToRtstruct } from "rt-convert-js";

const seg = readSeg(segBytes);
const { bytes, provenance } = await segToRtstruct(seg, 1, { interpretedType: "GTV" });

provenance.lossySteps[0];
// { kind: "mask-vectorization", voxelsBefore, voxelsAfter, voxelDisagreement, dice, detail }
// — segToRtstruct re-rasterizes what it wrote and reports the fidelity of *this* structure

For a FRACTIONAL SEG, pass threshold (a voxel is kept when its value is >= it); MissingThresholdError if you don't. thresholdScale is "unit" (default, against the [0,1] field) or "raw" (against the stored integers). The result then carries two lossy steps — fractional-threshold then mask-vectorization:

const { provenance } = await segToRtstruct(seg, 1, { threshold: 0.5 });
provenance.lossySteps[0];
// { kind: "fractional-threshold", threshold: 0.5, thresholdScale: "unit",
//   fractionalType: "PROBABILITY", maximumFractionalValue: 255, voxelsBefore, voxelsAfter, detail }

rt-convert-js does not re-export rtstruct-js or dicom-seg-js (they each re-export all of rt-geometry-js, so re-exporting both would collide). Import RTStruct, readSeg, and the geometry types from those packages directly.

License

MIT