On Saturday, November 23, 2019 at 3:27:05 PM UTC-7, Erik J wrote:
>
> 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
>
>
> 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
 

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pyqtgraph/bb7a9703-a6f3-4916-95f1-b8c36b269349%40googlegroups.com.

Reply via email to