Hi @zivy! It is good to see you again.
i managed to fix this today this way:
public static Image applyItkWCWW(Image image, double wc, double ww) {
IntensityWindowingImageFilter filter = new IntensityWindowingImageFilter();
filter.setOutputMinimum(0);
filter.setOutputMaximum(255);
double windowMin = wc - (ww/2);
double windowMax = wc + (ww/2);
long[] pixelRange = PixelIDValueEnumMap.getPixelIDByName(image.getPixelID()).getPixelRange();
double windowRangeMin = pixelRange[0];
double windowRangeMax = pixelRange[1];
filter.setWindowMinimum(Math.max(windowMin, windowRangeMin));
filter.setWindowMaximum(Math.min(windowMax, windowRangeMax));
return filter.execute(image);
}
public enum PixelIDValueEnumMap {
Unknown("sitkUnknown", new long[]{-32768, 32767}, (image, vector) -> "unknown"),
UInt8("sitkUInt8", new long[]{0, 255}, (image, vector) -> String.valueOf(image.getPixelAsUInt8(vector))),
Int8("sitkInt8", new long[]{-128, 127}, (image, vector) -> String.valueOf(image.getPixelAsInt8(vector))),
UInt16("sitkUInt16", new long[]{0, 65535}, (image, vector) -> String.valueOf(image.getPixelAsUInt16(vector))),
Int16("sitkInt16", new long[]{-32768, 32767}, (image, vector) -> String.valueOf(image.getPixelAsInt16(vector))),
UInt32("sitkUInt32", new long[]{0, 4_294_967_295L}, (image, vector) -> String.valueOf(image.getPixelAsUInt32(vector))),
Int32("sitkInt32", new long[]{-2_147_483_648L, 2_147_483_647L}, (image, vector) -> String.valueOf(image.getPixelAsInt32(vector))),
UInt64("sitkUInt64", new long[]{0, 9_223_372_036_854_775_807L}, (image, vector) -> String.valueOf(image.getPixelAsUInt64(vector))),
Int64("sitkInt64", new long[]{-9_223_372_036_854_775_807L, 9_223_372_036_854_775_807L}, (image, vector) -> String.valueOf(image.getPixelAsInt64(vector))),
Float32("sitkFloat32", new long[]{-32768, 32767}, (image, vector) -> String.valueOf(image.getPixelAsComplexFloat32(vector))),
Float64("sitkFloat64", new long[]{-32768, 32767}, (image, vector) -> String.valueOf(image.getPixelAsComplexFloat64(vector))),
ComplexFloat32("sitkComplexFloat32", new long[]{-32768, 32767}, (image, vector) -> String.valueOf(image.getPixelAsComplexFloat32(vector))),
ComplexFloat64("sitkComplexFloat64", new long[]{-32768, 32767}, (image, vector) -> String.valueOf(image.getPixelAsComplexFloat64(vector))),
VectorUInt8("sitkVectorUInt8", new long[]{-32768, 32767}, (image, vector) -> String.valueOf(image.getPixelAsVectorUInt8(vector))),
VectorInt8("sitkVectorInt8", new long[]{-32768, 32767}, (image, vector) -> String.valueOf(image.getPixelAsVectorInt8(vector))),
VectorUInt16("sitkVectorUInt16", new long[]{-32768, 32767}, (image, vector) -> String.valueOf(image.getPixelAsVectorUInt16(vector))),
VectorInt16("sitkVectorInt16", new long[]{-32768, 32767}, (image, vector) -> String.valueOf(image.getPixelAsVectorInt16(vector))),
VectorUInt32("sitkVectorUInt32", new long[]{-32768, 32767}, (image, vector) -> String.valueOf(image.getPixelAsVectorUInt32(vector))),
VectorInt32("sitkVectorInt32", new long[]{-32768, 32767}, (image, vector) -> String.valueOf(image.getPixelAsVectorInt32(vector))),
VectorUInt64("sitkVectorUInt64", new long[]{-32768, 32767}, (image, vector) -> String.valueOf(image.getPixelAsVectorUInt64(vector))),
VectorInt64("sitkVectorInt64", new long[]{-32768, 32767}, (image, vector) -> String.valueOf(image.getPixelAsVectorInt64(vector))),
VectorFloat32("sitkVectorFloat32", new long[]{-32768, 32767}, (image, vector) -> String.valueOf(image.getPixelAsVectorFloat32(vector))),
VectorFloat64("sitkVectorFloat64", new long[]{-32768, 32767}, (image, vector) -> String.valueOf(image.getPixelAsVectorFloat64(vector))),
LabelUInt8("sitkLabelUInt8", new long[]{-32768, 32767}, (image, vector) -> "LabelUInt8"),
LabelUInt16("sitkLabelUInt16", new long[]{-32768, 32767}, (image, vector) -> "LabelUInt16"),
LabelUInt32("sitkLabelUInt32", new long[]{-32768, 32767}, (image, vector) -> "LabelUInt32"),
LabelUInt64("sitkLabelUInt64", new long[]{-32768, 32767}, (image, vector) -> "LabelUInt64");
@Getter private final String name;
@Getter private final long[] pixelRange;
@Getter private final GetPixel getPixelLambda;
PixelIDValueEnumMap(String name, long[] pixelRange, GetPixel getPixelLambda) {
this.name = name;
this.pixelRange = pixelRange;
this.getPixelLambda = getPixelLambda;
}
public static PixelIDValueEnumMap getPixelIDByName (PixelIDValueEnum pixelID) {
String pixelIDString = pixelID.toString();
for (PixelIDValueEnumMap pixelIDMap : PixelIDValueEnumMap.values()) {
if (pixelIDMap.name.equals(pixelIDString)) {
return pixelIDMap;
}
}
return PixelIDValueEnumMap.Unknown;
}
}
After I solved it I saw your answer, it’s basically your way but done manually lol.
Thanks!