Skip to content

Commit

Permalink
Exclude private content sequences from the original metadata table
Browse files Browse the repository at this point in the history
The `getTags()` method still includes these sequences, but this just
keeps the original metadata table a little easier to read.
Private content sequences are detected by looking for a
private content creator, then excluding any sequences with a matching
high word. This corresponds to https://dicom.nema.org/dicom/2013/output/chtml/part05/sect_7.8.html
  • Loading branch information
melissalinkert committed Apr 1, 2024
1 parent acd37a1 commit daaa2f9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
11 changes: 11 additions & 0 deletions components/formats-bsd/src/loci/formats/dicom/DicomTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,17 @@ else if (!(value instanceof long[])) {
}
}

/**
* See https://dicom.nema.org/dicom/2013/output/chtml/part05/sect_7.8.html
*
* @return true if this is a private content creator tag
*/
public boolean isPrivateContentCreator() {
int highWord = (tag >> 16) & 0xffff;
int lowWord = tag & 0xffff;
return highWord % 2 == 1 && lowWord == 0x0010;
}

@Override
public String toString() {
if (key == null) {
Expand Down
12 changes: 11 additions & 1 deletion components/formats-bsd/src/loci/formats/in/DicomReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
Expand Down Expand Up @@ -127,6 +129,8 @@ public class DicomReader extends SubResolutionFormatReader {

private List<DicomTag> tags;

private Set<Integer> privateContentHighWords = new HashSet<Integer>();

// -- Constructor --

/** Constructs a new DICOM reader. */
Expand Down Expand Up @@ -368,6 +372,7 @@ public void close(boolean fileOnly) throws IOException {
concatenationNumber = null;
edf = false;
tags = null;
privateContentHighWords.clear();
}
}

Expand Down Expand Up @@ -1168,6 +1173,10 @@ else if (infoString.startsWith("MONOCHROME")) {
* rely upon the original metadata table.
*/
private void addOriginalMetadata(String key, DicomTag info) {
if (info.isPrivateContentCreator()) {
privateContentHighWords.add(info.tag >> 16);
}

if (info.value != null && !(info.value instanceof byte[]) &&
!(info.value instanceof short[]))
{
Expand All @@ -1179,7 +1188,8 @@ private void addOriginalMetadata(String key, DicomTag info) {
}
}
if (info.attribute != PER_FRAME_FUNCTIONAL_GROUPS_SEQUENCE &&
info.attribute != REFERENCED_IMAGE_NAVIGATION_SEQUENCE)
info.attribute != REFERENCED_IMAGE_NAVIGATION_SEQUENCE &&
!privateContentHighWords.contains(info.tag >> 16))
{
for (DicomTag child : info.children) {
String childKey = DicomAttribute.formatTag(child.tag);
Expand Down

0 comments on commit daaa2f9

Please sign in to comment.