Skip to content

TransformedServerBuilder.subtractOffset() is throwing IllegalArgumentException #1976

@Rdornier

Description

@Rdornier

Bug report

Describe the bug

Using the methods .subtractOffset(100) and .subtractOffsetAndClipZero(10) when creating a new TransformedServerBuilder() are throwing the following exception

ERROR: JSON forbids NaN and infinities: -Infinity
java.lang.IllegalArgumentException: JSON forbids NaN and infinities: -Infinity
    at com.google.gson.internal.bind.JsonTreeWriter.value(JsonTreeWriter.java:201)
    at com.google.gson.internal.bind.TypeAdapters$13.write(TypeAdapters.java:418)
    at com.google.gson.internal.bind.TypeAdapters$13.write(TypeAdapters.java:403)
    at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:73)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$2.write(ReflectiveTypeAdapterFactory.java:251)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:493)
    at com.google.gson.TypeAdapter.toJsonTree(TypeAdapter.java:181)
    at qupath.lib.io.GsonTools$SubTypeAdapterFactory$SubTypeAdapter.write(GsonTools.java:232)
    at com.google.gson.TypeAdapter$NullSafeTypeAdapter.write(TypeAdapter.java:304)
    at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:73)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$2.write(ReflectiveTypeAdapterFactory.java:251)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:493)
    at com.google.gson.TypeAdapter.toJsonTree(TypeAdapter.java:181)
    at qupath.lib.io.GsonTools$SubTypeAdapterFactory$SubTypeAdapter.write(GsonTools.java:232)
    at com.google.gson.TypeAdapter$NullSafeTypeAdapter.write(TypeAdapter.java:304)
    at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:73)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$2.write(ReflectiveTypeAdapterFactory.java:251)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:493)
    at com.google.gson.internal.bind.ObjectTypeAdapter.write(ObjectTypeAdapter.java:184)
    at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:73)
    at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:100)
    at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:64)
    at com.google.gson.Gson.toJson(Gson.java:944)
    at com.google.gson.Gson.toJsonTree(Gson.java:802)
    at com.google.gson.Gson.toJsonTree(Gson.java:779)
    at qupath.lib.projects.DefaultProject.writeProject(DefaultProject.java:1001)
    at qupath.lib.projects.DefaultProject.syncChanges(DefaultProject.java:344)
    at qupath.lib.gui.panes.ProjectBrowser.syncProject(ProjectBrowser.java:779)
    at qupath.lib.gui.panes.ProjectBrowser.ensureServerInWorkspace(ProjectBrowser.java:865)
    at qupath.lib.gui.panes.ProjectBrowser.changed(ProjectBrowser.java:889)
    at qupath.lib.gui.panes.ProjectBrowser.changed(ProjectBrowser.java:138)
    at [email protected]/com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent(ExpressionHelper.java:386)
    at [email protected]/com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:91)
    at [email protected]/javafx.beans.property.ObjectPropertyBase.fireValueChangedEvent(ObjectPropertyBase.java:106)
    at [email protected]/javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:113)
    at [email protected]/javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:147)
    at qupath.lib.gui.viewer.ViewerManager.imageDataChanged(ViewerManager.java:583)
    at qupath.lib.gui.viewer.QuPathViewer.fireImageDataChanged(QuPathViewer.java:1698)
    at qupath.lib.gui.viewer.QuPathViewer.setImageData(QuPathViewer.java:1584)
    at org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:321)
    at QuPathScript$_run_closure1.doCall(QuPathScript:21)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:343)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:328)
    at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:280)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1007)
    at groovy.lang.Closure.call(Closure.java:433)
    at groovy.lang.Closure.call(Closure.java:412)
    at groovy.lang.Closure.run(Closure.java:505)
    at [email protected]/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:456)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
    at [email protected]/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:455)
    at [email protected]/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at [email protected]/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at [email protected]/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
    at java.base/java.lang.Thread.run(Thread.java:1583)

To Reproduce

Steps to reproduce the behavior:

  1. Open a multichannel image
  2. Run the following script
// Set the ImageServer of the original image
def originalServer = getCurrentServer()
def originalImageData = getCurrentImageData()


def channels = []

for (int c = 0; c < originalServer.nChannels(); c++) {
    channels.add(ColorTransforms.createChannelExtractor(c))
}

def newServer = new TransformedServerBuilder(originalServer)
                .applyColorTransforms(channels)
                .subtractOffset(1)
                .build() 

def imageData = new ImageData<>(newServer)

// display image in the project
Platform.runLater(() -> getCurrentViewer().setImageData(imageData))

return
  1. See error in the logger

Possible fix

Instead of using Double.NEGATIVE_INFINITY or Double.POSITIVE_INFINITY on those lines, which, apparently is the cause of the above issue, replacing them by -Double.MAX_VALUE and Double.MAX_VALUE should correct this behavior.

Desktop

  • OS: Windows
  • QuPath Version: 0.6.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions