Skip to content

Commit

Permalink
Set a function for minimal rescale slope value
Browse files Browse the repository at this point in the history
  • Loading branch information
nroduit committed Jan 31, 2025
1 parent fa4aa26 commit 2db06e7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,8 @@ public LookupTableCV getModalityLookup(WlPresentation wlp, boolean inverseLUTAct
public boolean isPhotometricInterpretationInverse(PresentationStateLut pr) {
Optional<String> prLUTShape = pr == null ? Optional.empty() : pr.getPrLutShapeMode();
PhotometricInterpretation p = desc.getPhotometricInterpretation();
return prLUTShape.map("INVERSE"::equals)
return prLUTShape
.map("INVERSE"::equals)
.orElseGet(() -> p == PhotometricInterpretation.MONOCHROME1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ public PlanarImage getPlanarImage(int frame, DicomImageReadParam param) throws I
}

OptionalDouble rescaleSlope = desc.getModalityLUT().getRescaleSlope();
if (rescaleSlope.isPresent() && rescaleSlope.getAsDouble() < 0.5) {
if (rescaleSlope.isPresent() && hasVerySmallOutputValues(rescaleSlope.getAsDouble())) {
double intercept = desc.getModalityLUT().getRescaleIntercept().orElse(0.0);
ImageCV dstImg = new ImageCV();
out.toImageCV().convertTo(dstImg, CvType.CV_32F, rescaleSlope.getAsDouble(), intercept);
Expand All @@ -435,6 +435,10 @@ public PlanarImage getPlanarImage(int frame, DicomImageReadParam param) throws I
return out;
}

static boolean hasVerySmallOutputValues(double rescaleSlope) {
return rescaleSlope < 0.5;
}

public PlanarImage getRawImage(int frame, DicomImageReadParam param) throws IOException {
if (dis == null) {
return getRawImageFromBytes(frame, param);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public static PlanarImage getModalityLutImage(

if (datatype >= CvType.CV_8U && datatype < CvType.CV_32S) {
OptionalDouble rescaleSlope = adapter.getImageDescriptor().getModalityLUT().getRescaleSlope();
if (rescaleSlope.isPresent() && rescaleSlope.getAsDouble() < 0.5) {
if (rescaleSlope.isPresent()
&& DicomImageReader.hasVerySmallOutputValues(rescaleSlope.getAsDouble())) {
double intercept =
adapter.getImageDescriptor().getModalityLUT().getRescaleIntercept().orElse(0.0);
ImageCV dstImg = new ImageCV();
Expand Down

0 comments on commit 2db06e7

Please sign in to comment.