Discussion:
[pyqtgraph] HistogramLUTWidget and black images
Luca Piazza
2018-02-19 09:43:37 UTC
Permalink
Hello everybody!

beginner here... ;)
I'm writing a little GUI in PYQT5 to display images and I'd like to add
this histogram function.
The problem arises when my images are almost or completely black.
In case of an image with all 0 pixels the histogram breaks my application
raising the following error:

File "C:\Program
Files\Python36\lib\site-packages\pyqtgraph\graphicsItems\ImageItem.py",
line 464, in getHistogram
bins = np.arange(mn, mx+1.01*step, step, dtype=np.int)
ValueError: arange: cannot compute length
In case of an image with very few counts the histogram breaks my
application raising the following error:

File "C:\Program
Files\Python36\lib\site-packages\numpy\lib\function_base.py", line 727, in
histogram
'`bins` must increase monotonically, when an array')
ValueError: `bins` must increase monotonically, when an array
Any idea for any solutions?
I don't have the knowledge, unfortunately, to modify the widget myself.

Thanks!
Luca


ps... I will prepare a minimal example in few hours, but I preferred to
post this first
--
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/9393c1b3-fbfc-4583-8374-b104c45606ba%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Jim Crowell
2018-10-10 14:05:16 UTC
Permalink
I've also run into this issue. The problem is in
pyqtgraph/graphicsItems/ImageItem.py, in getHistogram():

if bins == 'auto':
mn = stepData.min()
mx = stepData.max()

...when mx == mn. I just added in immediately after that:


if mx == mn:
mx += 1
Post by Luca Piazza
Hello everybody!
beginner here... ;)
I'm writing a little GUI in PYQT5 to display images and I'd like to add
this histogram function.
The problem arises when my images are almost or completely black.
In case of an image with all 0 pixels the histogram breaks my application
File "C:\Program
Files\Python36\lib\site-packages\pyqtgraph\graphicsItems\ImageItem.py",
line 464, in getHistogram
bins = np.arange(mn, mx+1.01*step, step, dtype=np.int)
ValueError: arange: cannot compute length
In case of an image with very few counts the histogram breaks my
File "C:\Program
Files\Python36\lib\site-packages\numpy\lib\function_base.py", line 727, in
histogram
'`bins` must increase monotonically, when an array')
ValueError: `bins` must increase monotonically, when an array
Any idea for any solutions?
I don't have the knowledge, unfortunately, to modify the widget myself.
Thanks!
Luca
ps... I will prepare a minimal example in few hours, but I preferred to
post this first
--
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/666d4a98-5bb7-4e4d-969e-4dc48d042872%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Jim Crowell
2018-10-10 14:09:55 UTC
Permalink
Oh, and BTW, the easiest way to demo the issue is to take
pyqtgrapy/examples/HistogramLUT.py and replace:

data = pg.gaussianFilter(np.random.normal(size=(256, 256, 3)), (20, 20, 0))
for i in range(32):
for j in range(32):
data[i*8, j*8] += .1




with:

data = np.zeros((256,256), dtype=np.uint8)
Post by Jim Crowell
I've also run into this issue. The problem is in
mn = stepData.min()
mx = stepData.max()
mx += 1
Post by Luca Piazza
Hello everybody!
beginner here... ;)
I'm writing a little GUI in PYQT5 to display images and I'd like to add
this histogram function.
The problem arises when my images are almost or completely black.
In case of an image with all 0 pixels the histogram breaks my application
File "C:\Program
Files\Python36\lib\site-packages\pyqtgraph\graphicsItems\ImageItem.py",
line 464, in getHistogram
bins = np.arange(mn, mx+1.01*step, step, dtype=np.int)
ValueError: arange: cannot compute length
In case of an image with very few counts the histogram breaks my
File "C:\Program
Files\Python36\lib\site-packages\numpy\lib\function_base.py", line 727, in
histogram
'`bins` must increase monotonically, when an array')
ValueError: `bins` must increase monotonically, when an array
Any idea for any solutions?
I don't have the knowledge, unfortunately, to modify the widget myself.
Thanks!
Luca
ps... I will prepare a minimal example in few hours, but I preferred to
post this first
--
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/093e5b14-0481-4357-aab6-3ec1e83fc899%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Patrick
2018-10-14 01:33:53 UTC
Permalink
Hi,

I think there's a bug in ImageItem.py when returning a histogram for images
with unsigned integer data types, and all pixels the same value.

Try changing line 495 in ImageItem.py from:
step = np.ceil((mx-mn) / 500.)
to
step = np.ceil((mx-mn) / 500.) if not (mx-mn) == 0 else 1

Patrick
Post by Jim Crowell
Oh, and BTW, the easiest way to demo the issue is to take
data = pg.gaussianFilter(np.random.normal(size=(256, 256, 3)), (20, 20, 0
))
data[i*8, j*8] += .1
data = np.zeros((256,256), dtype=np.uint8)
Post by Jim Crowell
I've also run into this issue. The problem is in
mn = stepData.min()
mx = stepData.max()
mx += 1
Post by Luca Piazza
Hello everybody!
beginner here... ;)
I'm writing a little GUI in PYQT5 to display images and I'd like to add
this histogram function.
The problem arises when my images are almost or completely black.
In case of an image with all 0 pixels the histogram breaks my
File "C:\Program
Files\Python36\lib\site-packages\pyqtgraph\graphicsItems\ImageItem.py",
line 464, in getHistogram
bins = np.arange(mn, mx+1.01*step, step, dtype=np.int)
ValueError: arange: cannot compute length
In case of an image with very few counts the histogram breaks my
File "C:\Program
Files\Python36\lib\site-packages\numpy\lib\function_base.py", line 727, in
histogram
'`bins` must increase monotonically, when an array')
ValueError: `bins` must increase monotonically, when an array
Any idea for any solutions?
I don't have the knowledge, unfortunately, to modify the widget myself.
Thanks!
Luca
ps... I will prepare a minimal example in few hours, but I preferred to
post this first
--
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/30c12b51-4d32-41bd-a191-8f0f9148ac24%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...