Repository navigation
Conversation
There was no way to build a Secondary Capture Image without assembling the dataset by hand - which is what #85 and #333 were both asking for, and what any screenshot, rendering, scanned document or photograph needs. It extends DerivedDataset rather than DerivedPixels, because the pixels are NOT derived from the reference: they are supplied by the caller, and nothing about the reference's pixel geometry, frame count or PixelData should be inherited. What the reference does give is the composite context, so the capture files alongside the images it relates to. const sc = new SecondaryCapture([referenceDataset], { SeriesDescription: "Screen capture" }); sc.setPixels({ rows: 768, columns: 1024, pixelData: rgbBytes }); const buffer = datasetToDict(sc.dataset).write(); setPixels() writes the whole Image Pixel module and validates against it: samples per pixel is inferred from the data length when not given, and a length that does not match rows x columns x samples x bytes is rejected rather than written as a malformed instance. Colour and grayscale, 8 and 16 bits. A view covering part of a larger buffer is copied out, so passing a subarray does not silently write the whole backing buffer. Three choices worth noting: - BurnedInAnnotation defaults to "YES". A screen capture normally has patient-identifying text drawn into it, and a de-identifier that trusts a "NO" here will pass the pixels through untouched. Overridable for a capture that genuinely carries none. - No FrameOfReferenceUID, ImagePositionPatient or ImageOrientationPatient, even when the reference has them. A Secondary Capture is a picture of a screen; inheriting those would invite a viewer to place it in space. - _meta.TransferSyntaxUID is pinned to Explicit VR Little Endian. DerivedDataset copies _meta from the reference and datasetToDict keeps whatever TransferSyntaxUID it finds there, so a reference read from an implicit VR file would otherwise make the capture implicit VR too. There is a test for that, built from an implicit VR reference. options.referencedSeries populates ReferencedSeriesSequence and ReferencedInstanceSequence (Common Instance Reference, PS3.3 C.12.2), so what a capture was made from is recorded in standard attributes. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
✅ Deploy Preview for dcmjs2 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
| rows, | ||
| columns, | ||
| pixelData, | ||
| samplesPerPixel, |
There was a problem hiding this comment.
I suggest deriving samplesPerPixel and photometric interpretation based on the pixelData provided. You should also be able to infer bitsAllocated that way.
| const bytesPerSample = bitsAllocated / 8; | ||
| const samples = | ||
| samplesPerPixel ?? | ||
| inferSamplesPerPixel( |
There was a problem hiding this comment.
I see you do have the infer samples per pixel here.
wayfarer3130
left a comment
There was a problem hiding this comment.
The 1.0-beta work changes how the derivations occur, with a bunch of classes to allow transforming/creating classes based on various pre-configured values. I think that ultimately makes more sense than this one.
As well, there are some issues with how this creates the object:
Wrong VR for 16-bit pixels. DerivedDataset shares its VR map (_vrMap) with the reference dataset. A 16-bit capture made from an 8-bit reference whose pixel data is OB gets written as OB, which DICOM doesn't allow above 8 bits.
Image type contradicts the PR. It writes ImageType DERIVED but no source sequence, although the PR says the pixels aren't derived from the reference.
Wrong default for MONOCHROME1. PresentationLUTShape is always IDENTITY, and the photometric value isn't checked against the number of samples.
Leftover research defaults. It keeps DerivedDataset's ImageComments, ContentQualification, SeriesNumber and SeriesDescription defaults.
Relates to #85 and #333, both asking how to make a DICOM image from a JPEG. There is currently no way to build a Secondary Capture Image without assembling the dataset by hand — which is also what any screenshot, rendering or scanned document needs.
Why
DerivedDatasetand notDerivedPixelsThe pixels are not derived from the reference — they are supplied by the caller, and nothing about the reference's pixel geometry, frame count or
PixelDatashould be inherited. What the reference does give is the composite context, so the capture files alongside the images it relates to. There is a test asserting a reference withRows: 512,NumberOfFrames: 100and its ownPixelDatacontributes none of that.setPixels()writes the whole Image Pixel module and validates against it: samples per pixel is inferred from the data length when not given, and a length that does not matchrows × columns × samples × bytesis rejected rather than written out as a malformed instance. Colour and grayscale, 8 and 16 bits. A view covering part of a larger buffer is copied out, so passing asubarraydoes not silently write the whole backing buffer.Three choices worth review
BurnedInAnnotationdefaults to"YES". A screen capture normally has patient-identifying text drawn into it, and a de-identifier that trusts a"NO"here will pass the pixels through untouched. Overridable for a capture that genuinely carries none. I would rather the safe default be the quiet one.FrameOfReferenceUID,ImagePositionPatientorImageOrientationPatient, even when the reference has them. A Secondary Capture is a picture of a screen; inheriting those would invite a viewer to place it in patient space._meta.TransferSyntaxUIDis pinned to Explicit VR Little Endian. This one is a trap rather than a preference:DerivedDatasetcopies_metafrom the reference, anddatasetToDictkeeps whateverTransferSyntaxUIDit finds there — so a reference read from an implicit VR file would silently make the capture implicit VR too. The test is built from an implicit-VR reference and fails if the pin is removed.options.referencedSeriespopulatesReferencedSeriesSequenceandReferencedInstanceSequence(Common Instance Reference, PS3.3 C.12.2), so what a capture was made from is recorded in standard attributes rather than left implicit.Tests
10 in
test/secondaryCapture.test.js: the SC attribute set, burned-in annotation defaulting, context-without-pixels, absence of spatial registration, the implicit-VR case, byte-exact colour round trip, grayscale and 16-bit, the validation failures, referenced instances surviving a write and read, and a partial buffer view.Full suite: 26 suites / 364 tests.
Disclosure
AI-assisted (Claude), per the process in #517. Written for a downstream project that needs a capture carrying a reserved private block (see #626), but the derivation itself is general and has no dependency on that.