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

floating point issue in FloatStatistics.java #25

Closed
krami79 opened this issue Nov 10, 2016 · 4 comments
Closed

floating point issue in FloatStatistics.java #25

krami79 opened this issue Nov 10, 2016 · 4 comments

Comments

@krami79
Copy link

krami79 commented Nov 10, 2016

It may be a very rare corner case, but in FloatStatistics.java there are
float v;
and
double v;
used in different places for the same purpose of holding a temporary copy of a float pixel value and doing range checks. It appears that the use of "double v" in line 50 could lead to inconsistent pixelCounts and then in turn the float[] pixels2 array from line 230 maybe too short. In particular I got the very strange Error when setting the pixels in a 512x512 32bit image without any ROIs or masks.

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 262143
at ij.process.FloatStatistics.getMedian(FloatStatistics.java:242)
at ij.process.FloatStatistics.(FloatStatistics.java:44)
at ij.process.ImageStatistics.getStatistics(ImageStatistics.java:82)
at ij.ImagePlus.getStatistics(ImagePlus.java:891)
at ij.ImagePlus.getStatistics(ImagePlus.java:863)
at ij.ImagePlus.getStatistics(ImagePlus.java:843)
at ij.plugin.frame.ContrastAdjuster.plotHistogram(ContrastAdjuster.java:610)
at ij.plugin.frame.ContrastAdjuster.setupNewImage(ContrastAdjuster.java:396)
at ij.plugin.frame.ContrastAdjuster.setup(ContrastAdjuster.java:317)
at ij.plugin.frame.ContrastAdjuster.setup(ContrastAdjuster.java:275)
at ij.plugin.frame.ContrastAdjuster.windowActivated(ContrastAdjuster.java:1149)
at java.awt.AWTEventMulticaster.windowActivated(AWTEventMulticaster.java:372)
at java.awt.Window.processWindowEvent(Window.java:1877)
at java.awt.Window.processEvent(Window.java:1823)
at java.awt.Component.dispatchEventImpl(Component.java:4652)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4482)
at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1850)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:910)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:409)
at java.awt.Component.dispatchEventImpl(Component.java:4524)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4482)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:644)
at java.awt.EventQueue.access$000(EventQueue.java:85)
at java.awt.EventQueue$1.run(EventQueue.java:603)
at java.awt.EventQueue$1.run(EventQueue.java:601)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
at java.awt.EventQueue$2.run(EventQueue.java:617)
at java.awt.EventQueue$2.run(EventQueue.java:615)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:614)
at java.awt.SentEvent.dispatch(SentEvent.java:55)
at java.awt.DefaultKeyboardFocusManager$DefaultKeyboardFocusManagerSentEvent.dispatch(DefaultKeyboardFocusManager.java:183)
at java.awt.DefaultKeyboardFocusManager.sendMessage(DefaultKeyboardFocusManager.java:210)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:286)
at java.awt.Component.dispatchEventImpl(Component.java:4524)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4482)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:644)
at java.awt.EventQueue.access$000(EventQueue.java:85)
at java.awt.EventQueue$1.run(EventQueue.java:603)
at java.awt.EventQueue$1.run(EventQueue.java:601)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
at java.awt.EventQueue$2.run(EventQueue.java:617)
at java.awt.EventQueue$2.run(EventQueue.java:615)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:614)
at java.awt.SequencedEvent.dispatch(SequencedEvent.java:101)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:642)
at java.awt.EventQueue.access$000(EventQueue.java:85)
at java.awt.EventQueue$1.run(EventQueue.java:603)
at java.awt.EventQueue$1.run(EventQueue.java:601)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
at java.awt.EventQueue$2.run(EventQueue.java:617)
at java.awt.EventQueue$2.run(EventQueue.java:615)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:614)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

@rasband
Copy link
Member

rasband commented Nov 10, 2016

Please upload a 32-bit image that I can use to reproduce this error.

@krami79
Copy link
Author

krami79 commented Nov 18, 2016

Hi Rasband

Thank you for looking into this matter,

I do get that error occasionally, but it is not related to the actual
floating point images. I am creating a new all black image
from within a plugin and show it on the screen. The pixel values are on
the fly updated (and also set) by an ongoing simulation. And if I hit
shift+ctrl+c to open the contrast&brightness adjuster, the error can
sometimes occur. But only if the B&C window does not yet exist.

it seems that the pixelCount as determined in getStatisics(...) is still
correctly width x height, but the count in getMedian actually exceeds
width x height. I just cannot see how on earth rw and rh could have
changed inbetween the two function calls. and to that matter the mixed
use of float and double is also fine, just a minor issue of style.
Whatever is going on would also apply to several places in
FloatStatistics.java

In my simulations i am keeping a local reference of the pixel array and
then use ImageStack.setPixels(n). I dont believe that I did put an
invalid array there. but to me it seems that the ImageStack.setPixels
function only checks the 1 based stack index. Neither has the type of
the array to match an already defined type nor has the length of the set
pixels match width*height. But I guess any of those would definitely
lead to a well reproducible major disaster.

Anyways, I cannot give you an image that would reproduce the error, so
we could as well close that issue. I am a heavy ImageJ user and only see
this error like once a week.

Cheers,
Christian

On 11/10/2016 08:10 PM, rasband wrote:

Please upload a 32-bit image that I can use to reproduce this error.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#25 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AVwpewP93rSEPHSrSihRcCvhL_-frlYfks5q82wjgaJpZM4Ku-9Q.

@rasband
Copy link
Member

rasband commented Nov 19, 2016

Upgrade to the latest ImageJ daily build (1.51i3) and you should no longer experience this error since the Brightness/Contrast adjuster no longer calculates the median.

@rasband rasband closed this as completed Nov 19, 2016
@krami79
Copy link
Author

krami79 commented Nov 21, 2016

Wow, this also had the nice side_effect of speeding up the B&C adjuster
a lot on larger images. Maybe there was even more useless statistics,
but for sure the median is the most heavy one;)

On 11/19/2016 05:04 AM, rasband wrote:

Upgrade to the latest ImageJ daily build (1.51i3) and you should no
longer experience this error since the Brightness/Contrast adjuster no
longer calculates the median.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#25 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AVwpe3O9ATnL7GLZ9eUcw975N-t13TxXks5q_nUygaJpZM4Ku-9Q.

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