In case someone asks the same question in the future...

I was asking the wrong question - I should have been trying to use 
something like _blur_ rather than antialias.
I posted the same question on stackoverflow: 
https://stackoverflow.com/questions/71268676/antialiasing-images-in-pyqtgraph-imageview

I just add the Qt graphics effect and apply this to the ImageItem within 
the ImageView.
https://doc.qt.io/qtforpython-5/PySide2/QtWidgets/QGraphicsEffect.html#more in 
case like me you didn't know anything about the Qt graphics effects.

My only problem now is that the blur seems to be a fairly expensive 
operation, and either I try to force use of hardware acceleration (how?) or 
I selectively enable blur- e.g. disable during pan/zoom and re-enable on 
releasing mouse buttons- however it is still slow to pan/zoom when zoomed 
in enough to enable blur.
I think I'm going to be forced into trying something like VisPy or VTK 
(which I'd rather not do) unless there are any suggestions here.

-Oli

On Sunday, February 20, 2022 at 4:47:52 PM UTC+8 Oli N wrote:

> Hi everyone-
>
> I hope someone can help me here.
>
> I am displaying 2D numpy arrays in an ImageView widget and am trying to 
> *antialias* the image - my users tend to zoom in and see the ugly pixels.
> [image: low-res-noAA.png]
> While I have seen people use this:
>
>     pg.setConfigOptions(antialias=True)
>  in conjunction with ImageItem within a GraphicsView, I owuld like to use 
> the volume view (with slider) that you get with the ImageView but you 
> don't get with ImageItem.
>
>
> I haven't found a way to antialias *image within an ImageView.*
>
> Perhaps there is something Qt/PySide or a more raw OpenGL option I can use 
> to do this?  Unfortunately I do not have a deep enough grasp on this to go 
> any further...
>
> Or perhaps I just don't know how to get the slider in the ImageItem to 
> view slices of a 3D dataset (a stack of 2d images in this case).
>
> Any help would be much appreciated.
>
> Cheers-
>  Oli
>
> here's my minimal code:
>
> import sys
> from PySide2.QtWidgets import (
>     QApplication,
>     QHBoxLayout,
>     QMainWindow,
>     QWidget,
> )
> import pyqtgraph as pg
> import numpy as np
>
> pg.setConfigOptions(antialias=True)
>
>
> class MainWindow(QMainWindow):
>     def __init__(self):
>         super().__init__()
>
>         self.cw = QWidget(self)
>         self.cw.setAutoFillBackground(True)
>         self.setCentralWidget(self.cw)
>
>         self.layout = QHBoxLayout()
>         self.cw.setLayout(self.layout)
>
>         self.DcmImgWidget = MyImageWidget(parent=self)
>         self.layout.addWidget(self.DcmImgWidget)
>
>         self.show()
>
>
> class MyImageWidget(pg.ImageView):
>     def __init__(self, parent=None):
>         super().__init__(parent)
>         self.ui.histogram.hide()
>         self.ui.roiBtn.hide()
>         self.ui.menuBtn.hide()
>
>         # 5 frames of 50x50 random noise ranging from -500 to 500
>         img = (1000 * np.random.normal(size=(5, 50, 50))) - 500
>         self.setImage(img)
>
>
> def main():
>     app = QApplication()
>     main = MainWindow()
>     main.show()
>     sys.exit(app.exec_())
>
>
> if __name__ == '__main__':
>     main()
>
>  
>

-- 
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/70d66d7a-1bc9-41d2-b83b-9837fc173564n%40googlegroups.com.

Reply via email to