Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot invoke "org.dcm4che3.opencv.StreamSegment.getImageDescriptor()" because "seg" is null #1403

Open
SaluRamos opened this issue Feb 24, 2024 · 3 comments

Comments

@SaluRamos
Copy link

SaluRamos commented Feb 24, 2024

Describe the bug

03:36:01.918 [main] DEBUG org.dcm4che3.imageio.plugins.dcm.DicomImageReader -- Decompressor: org.dcm4che3.opencv.NativeImageReader
03:36:01.923 [main] DEBUG org.dcm4che3.imageio.plugins.dcm.DicomImageReader -- Start decompressing frame #1
03:36:01.952 [main] ERROR org.dcm4che3.opencv.StreamSegment -- Building FileStreamSegment from SegmentedInputImageStream
java.lang.reflect.InaccessibleObjectException: Unable to make field private java.io.RandomAccessFile javax.imageio.stream.FileCacheImageInputStream.cache accessible: module java.desktop does not "opens javax.imageio.stream" to module dcm4che.imageio.opencv
	at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
	at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
	at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:178)
	at java.base/java.lang.reflect.Field.setAccessible(Field.java:172)
	at dcm4che.imageio.opencv@5.31.2/org.dcm4che3.opencv.StreamSegment.getFileStreamSegment(StreamSegment.java:129)
	at dcm4che.imageio.opencv@5.31.2/org.dcm4che3.opencv.StreamSegment.getStreamSegment(StreamSegment.java:98)
	at dcm4che.imageio.opencv@5.31.2/org.dcm4che3.opencv.NativeImageReader.getNativeImage(NativeImageReader.java:260)
	at dcm4che.imageio.opencv@5.31.2/org.dcm4che3.opencv.NativeImageReader.read(NativeImageReader.java:251)
	at dcm4che.imageio@5.31.2/org.dcm4che3.imageio.plugins.dcm.DicomImageReader.readRaster(DicomImageReader.java:375)
	at com.webkriativa.noahviewer@0.4/com.webkriativa.noahviewer.graphics.FrameSetVolume.loadHounsfieldValue(FrameSetVolume.java:98)
	at com.webkriativa.noahviewer@0.4/com.webkriativa.noahviewer.graphics.FrameSetVolume.<init>(FrameSetVolume.java:35)
	at com.webkriativa.noahviewer@0.4/com.webkriativa.noahviewer.MRETest.loadImage(MRETest.java:68)
	at com.webkriativa.noahviewer@0.4/com.webkriativa.noahviewer.MRETest.main(MRETest.java:25)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:465)
	at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:364)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1085)

fev. 24, 2024 3:36:01 AM org.opencv.osgi.OpenCVNativeLoader init
INFO: Successfully loaded OpenCV native library.
java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:465)
	at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:364)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1085)
Caused by: java.lang.NullPointerException: Cannot invoke "org.dcm4che3.opencv.StreamSegment.getImageDescriptor()" because "seg" is null
	at dcm4che.imageio.opencv@5.31.2/org.dcm4che3.opencv.NativeImageReader.getNativeImage(NativeImageReader.java:261)
	at dcm4che.imageio.opencv@5.31.2/org.dcm4che3.opencv.NativeImageReader.read(NativeImageReader.java:251)
	at dcm4che.imageio@5.31.2/org.dcm4che3.imageio.plugins.dcm.DicomImageReader.readRaster(DicomImageReader.java:375)

Java correto 17.0.9, with gradle and modules. i just downloaded last dcm4che release 5.31.2.

this is my build.gradle

plugins {
    id "java"
    id "application"
    id "org.javamodularity.moduleplugin" version "1.8.12"
}

group "com.myapp"
version "0.1"

repositories {
    mavenCentral()
}

sourceCompatibility = "17"
targetCompatibility = "17"

tasks.withType(JavaCompile).configureEach {
    options.encoding = "UTF-8"
}

application {
    mainModule = "com.webkriativa.noahviewer"
    mainClass = "com.webkriativa.noahviewer.Main"
}

dependencies {
    implementation files("libs/dcm4che-5.31.2/lib/angus-activation-2.0.1.jar")
    implementation files("libs/dcm4che-5.31.2/lib/clibwrapper_jiio-1.2-pre-dr-b04.jar")
    implementation files("libs/dcm4che-5.31.2/lib/commons-cli-1.6.0.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-audit-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-conf-api-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-conf-api-hl7-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-conf-ldap-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-conf-ldap-audit-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-conf-ldap-hl7-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-conf-ldap-imageio-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-core-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-dcmr-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-deident-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-dict-priv-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-emf-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-hl7-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-image-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-imageio-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-imageio-opencv-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-imageio-rle-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-json-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-mime-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-net-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-net-audit-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-net-hl7-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-qstar-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-soundex-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-agfa2dcm-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-agfa2sr-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-common-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-dcm2dcm-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-dcm2jpg-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-dcm2json-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-dcm2pdf-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-dcm2str-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-dcm2xml-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-dcmassoc-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-dcmbenchmark-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-dcmdir-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-dcmdump-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-dcmldap-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-dcmqrscp-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-dcmvalidate-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-deidentify-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-emf2sf-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-findscu-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-fixlo2un-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-getscu-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-hl72xml-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-hl7pdq-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-hl7pix-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-hl7rcv-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-hl7snd-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-ianscp-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-ianscu-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-ihe-modality-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-jpg2dcm-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-json2dcm-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-json2index-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-json2props-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-json2rst-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-maskpxdata-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-mkkos-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-movescu-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-mppsscp-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-mppsscu-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-pdf2dcm-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-planarconfig-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-qstar-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-stgcmtscu-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-storescp-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-storescu-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-stowrs-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-stowrsd-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-swappxdata-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-syslog-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-syslogd-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-tpl2xml-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-upsscu-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-wadors-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-wadows-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-xml2dcm-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-xml2hl7-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-tool-xroad-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-ws-rs-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-xdsi-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/dcm4che-xroad-5.31.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/gmbal-api-only-4.0.3.jar")
    implementation files("libs/dcm4che-5.31.2/lib/istack-commons-runtime-4.1.1.jar")
//    implementation files("libs/dcm4che-5.31.2/lib/jai_imageio-1.2-pre-dr-b04.jar")
    implementation files("libs/dcm4che-5.31.2/lib/jakarta.activation-api-2.1.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/jakarta.json-api-2.1.2.jar")
    implementation files("libs/dcm4che-5.31.2/lib/jakarta.xml.bind-api-4.0.0.jar")
    implementation files("libs/dcm4che-5.31.2/lib/jakarta.xml.soap-api-3.0.0.jar")
    implementation files("libs/dcm4che-5.31.2/lib/jakarta.xml.ws-api-4.0.0.jar")
    implementation files("libs/dcm4che-5.31.2/lib/jaxb-core-4.0.1.jar")
    implementation files("libs/dcm4che-5.31.2/lib/jaxb-runtime-4.0.1.jar")
    implementation files("libs/dcm4che-5.31.2/lib/logback-classic-1.4.14.jar")
    implementation files("libs/dcm4che-5.31.2/lib/logback-core-1.4.14.jar")
    implementation files("libs/dcm4che-5.31.2/lib/mimepull-1.10.0.jar")
    implementation files("libs/dcm4che-5.31.2/lib/parsson-1.1.3.jar")
    implementation files("libs/dcm4che-5.31.2/lib/policy-4.0.0.jar")
    implementation files("libs/dcm4che-5.31.2/lib/rt-4.0.0.jar")
    implementation files("libs/dcm4che-5.31.2/lib/saaj-impl-3.0.0.jar")
    implementation files("libs/dcm4che-5.31.2/lib/slf4j-api-2.0.9.jar")
    implementation files("libs/dcm4che-5.31.2/lib/stax-ex-2.1.0.jar")
    implementation files("libs/dcm4che-5.31.2/lib/streambuffer-2.1.0.jar")
    implementation files("libs/dcm4che-5.31.2/lib/weasis-core-img-4.8.1.jar")

    compileOnly("org.projectlombok:lombok:1.18.28")
    annotationProcessor("org.projectlombok:lombok:1.18.28")
    testCompileOnly("org.projectlombok:lombok:1.18.28")
    testAnnotationProcessor("org.projectlombok:lombok:1.18.28")
}

run {
    jvmArgs = ['-Djava.library.path="libs/dcm4che-5.31.2/lib/windows-x86-64"', '--add-opens', 'java.desktop/javax.imageio.stream=ALL-UNNAMED', '--add-opens', 'java.' +
            'base/java.io=ALL-UNNAMED']
}

my module-info.java

module com.webkriativa.noahviewer {
    requires static lombok;
    requires dcm4che.core;
    requires dcm4che.image;
    requires dcm4che.imageio;
    requires dcm4che.imageio.opencv;
    requires org.slf4j;
    requires java.desktop;
}

code is:

try (DicomInputStream dis = new DicomInputStream(new File("some_dicom_file.dcm"))) {
            ImageReader reader = ImageIO.getImageReadersByFormatName("DICOM").next();
            try (ImageInputStream iis = ImageIO.createImageInputStream(dis)) {
                reader.setInput(iis, false);
                ImageReadParam param = reader.getDefaultReadParam();
                // note that a file may have multiple frames.
                // set frame number depending on your use case
                int frame = 0;
                Raster raster = reader.readRaster(frame, param);
                System.out.println(raster);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
@nroduit
Copy link
Member

nroduit commented Feb 24, 2024

Integration with a Java module is different from that of the classpath. You need to specify accesses, see this post.

@SaluRamos
Copy link
Author

SaluRamos commented Feb 24, 2024

Thanks for responding @nroduit , I've never worked with modules before, so I have some lay questions. from what I understand, in my module-info.java I can only open and export packages that I created, when I try to open java.desktop for javax.imageio.stream it says package not found for both.

module com.webkriativa.noahviewer {
requires static lombok;
requires dcm4che.core;
requires dcm4che.image;
requires dcm4che.imageio;
requires dcm4che.imageio.opencv;
requires org.slf4j;
requires java.desktop;
opens java.desktop to javax.imageio.stream;
}

@SaluRamos
Copy link
Author

SaluRamos commented Feb 24, 2024

Integration with a Java module is different from that of the classpath. You need to specify accesses, see this post.

After studying more about modules I managed to understand my error and solved it as follows:

jvmArgs = ['--add-opens', 'java.desktop/javax.imageio.stream=dcm4che.imageio.opencv',
'--add-opens', 'java.base/java.io=dcm4che.imageio.opencv']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants