fiji / Kappa

A Fiji plugin for Curvature Analysis
MIT License
7 stars 1 forks source link

Issues with image size and zoom #10

Open lenlabcangay opened 1 year ago

lenlabcangay commented 1 year ago

Hello, I am testing your tool, and I think that it works great. However, is it possible to fix these issues?

imagejan commented 1 year ago

FWIW, I can reproduce the issue with the "Fluorescent Cells" sample image after scaling it from 512x512 to a size of 2048x2048.

Here's the stack trace when I try to open that size-adjusted image in Kappa:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Width (0) and height (0) cannot be <= 0
    at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1016)
    at java.awt.GraphicsConfiguration.createCompatibleImage(GraphicsConfiguration.java:150)
    at java.awt.GraphicsConfiguration.createCompatibleImage(GraphicsConfiguration.java:178)
    at sc.fiji.kappa.gui.KappaFrame.setScaledImage(KappaFrame.java:417)
    at sc.fiji.kappa.gui.ControlPanel$ScaleChanger.stateChanged(ControlPanel.java:215)
    at javax.swing.JSlider.fireStateChanged(JSlider.java:432)
    at javax.swing.JSlider$ModelListener.stateChanged(JSlider.java:350)
    at javax.swing.DefaultBoundedRangeModel.fireStateChanged(DefaultBoundedRangeModel.java:364)
    at javax.swing.DefaultBoundedRangeModel.setRangeProperties(DefaultBoundedRangeModel.java:302)
    at javax.swing.DefaultBoundedRangeModel.setMaximum(DefaultBoundedRangeModel.java:219)
    at javax.swing.JSlider.setMaximum(JSlider.java:619)
    at sc.fiji.kappa.gui.KappaMenuBar.openImage(KappaMenuBar.java:636)
    at sc.fiji.kappa.gui.KappaMenuBar.openActiveImage(KappaMenuBar.java:574)
    at sc.fiji.kappa.gui.KappaMenuBar.lambda$new$0(KappaMenuBar.java:151)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    at javax.swing.AbstractButton.doClick(AbstractButton.java:376)
    at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:842)
    at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:886)
    at java.awt.Component.processMouseEvent(Component.java:6539)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
    at java.awt.Component.processEvent(Component.java:6304)
    at java.awt.Container.processEvent(Container.java:2239)
    at java.awt.Component.dispatchEventImpl(Component.java:4889)
    at java.awt.Container.dispatchEventImpl(Container.java:2297)
    at java.awt.Component.dispatchEvent(Component.java:4711)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4904)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4535)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4476)
    at java.awt.Container.dispatchEventImpl(Container.java:2283)
    at java.awt.Window.dispatchEventImpl(Window.java:2746)
    at java.awt.Component.dispatchEvent(Component.java:4711)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:760)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:84)
    at java.awt.EventQueue$4.run(EventQueue.java:733)
    at java.awt.EventQueue$4.run(EventQueue.java:731)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:730)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
scuniff commented 1 year ago

I was able to re-produce the stack trace mentioned above using these steps:

  1. Open up Samples->Fluorescent Cells
  2. Image->Scale to 2048x2048
  3. Left click on 2048x2048 image
  4. Plugins->Analyze->Kappa – Curvature Analysis
  5. In Kappa, Select Active Image
  6. Stack trace appears in console.

I attached Eclipse IDE to Fiji and did some debugging. I came across this code in KappaMenuBar.java(https://github.com/fiji/Kappa/blob/master/src/main/java/sc/fiji/kappa/gui/KappaMenuBar.java), line 630:

// Sets the maximum scale to a value that prevents a heap space error from
// occurring.
// We set the maximum image size to about 2000 x 2000 pixels = 4,000,000 pixels.
int avgPixelDim = (frame.getCurrImage().getWidth() + frame.getCurrImage().getHeight()) / 2;
    frame.getControlPanel().getScaleSlider().setValue(ControlPanel.DEFAULT_SCALE);
frame.getControlPanel().getScaleSlider()
            .setMaximum(Math.min(ControlPanel.MAX_SCALE, ControlPanel.MAX_AVG_PIXEL_DIM / avgPixelDim * 100));

Looking at the last statement:

     frame.getControlPanel().getScaleSlider()
            .setMaximum(Math.min(ControlPanel.MAX_SCALE, ControlPanel.MAX_AVG_PIXEL_DIM / avgPixelDim * 100));

the constant variable ControlPanel.MAX_AVG_PIXEL_DIM is permanently set to 2000 in another file. The variable avgPixelDim is 2048 when I do the above steps. So, the Integer division result is 0, thus the exception occurs:

    Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Width (0) and height (0) cannot be <= 0

When I change ControlPanel.MAX_AVG_PIXEL_DIM to 2500(which is greater than 2048), the Integer division is no longer 0 and the exception no longer occurs.

I don’t know Kappa at all to know if everything is working correctly, all I know there’s no exception.