ImageItem crashes in getHostogram()

26 views
Skip to first unread message

Erik J

unread,
Nov 23, 2019, 5:27:05 PM11/23/19
to pyqtgraph
Hi everyone,

I am using a HistogramLutWidget for an image that is displayed in a pg.GraphicsLayoutWidget. The image is a dark and gain corrected image from a CCD camera that updates in real time as it is received from the camera. The problem I am having is that the ImageItem in the histogram display will crash periodically in the method getHistogram(). This occurs if the min and max of the image are the same. Here is the code snippet from getHistogram:

        if bins == 'auto':
            if stepData.dtype.kind in "ui":
                mn = stepData.min()
                mx = stepData.max()
                step = np.ceil((mx-mn) / 500.)
                bins = np.arange(mn, mx+1.01*step, step, dtype=np.int)
                if len(bins) == 0:
                    bins = [mn, mx]
            else:
                bins = 500

If mn and mx are equal, then np.arange() fails with an error. I suggest the following code change to fix the problem:
        if bins == 'auto':
            if stepData.dtype.kind in "ui":
                mn = stepData.min()
                mx = stepData.max()
                step = np.ceil((mx-mn) / 500.)

                bins = np.arange(mn, mx+1.01*step, step, dtype=np.int)
                if len(bins) == 0:
                    bins = [mn, mx]
            else:
                bins = 500



Erik J

unread,
Nov 23, 2019, 5:29:56 PM11/23/19
to pyqtgraph
Sorry, somehow this got posted before I was finished. The new code should be:

        if bins == 'auto':
           
if stepData.dtype.kind in "ui":
                mn
= stepData.min()
                mx
= stepData.max()
                step
= np.ceil((mx-mn) / 500.)

               
if step == 0: step = 1.0

                bins
= np.arange(mn, mx+1.01*step, step, dtype=np.int)
               
if len(bins) == 0:
                    bins
= [mn, mx]
           
else:
                bins
= 500


Please let me know if anyone else has experienced this problem. It can easily occur if an image is saturated or if nearly all the pixels are zero.

Thanks,
Erik
 

Kenneth Lyons

unread,
Nov 23, 2019, 10:23:33 PM11/23/19
to pyqtgraph
Hi Erik, I believe this is the same issue reported here: https://github.com/pyqtgraph/pyqtgraph/issues/1033

The comments there are still accurate (fixed version not released yet), but there are instructions for installing pyqtgraph via git.

Hope that helps.

- Kenny

Erik Johansson

unread,
Nov 24, 2019, 1:45:06 PM11/24/19
to pyqt...@googlegroups.com
Thanks, Kenny! That indeed is the same problem. The mx+= 1 fix you implemented looks fine to me. Thanks for the help.
Erik

--
You received this message because you are subscribed to the Google Groups "pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyqtgraph+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/d6dfc5ad-8fda-45ab-9531-81f84fa5a89b%40googlegroups.com.


--
************************************************
Erik Johansson
Project Manager, Wavefront Correction System
National Solar Observatory
Daniel K Inouye Solar Telescope
3665 Discovery Drive, Boulder, CO 80303
Tel: 303-735-7723
************************************************
Reply all
Reply to author
Forward
0 new messages