adding text values on top of pixels in ImageItem

143 views
Skip to first unread message

Kuba Raczkowski

unread,
Dec 15, 2017, 10:10:09 AM12/15/17
to pyqtgraph
Hi,

I'm trying to annotate the ImageItem's pixels by a textual value on top of every pixel. 
Got it working by extending the paint() and adding necessary drawText() calls, however, the performance is (obviously?) terrible.

This is only meant to be useful when zooming in deeply - that I can treshold by figuring out pixelSize() of ImageItem.

However, all labels seem to be painted even if only a few pixels are visible in the view. 
Any idea how to figure out the pixels (or a rectangle) that are actually visible in the view? I'm getting lost in all the coordinate mappings :/


Best regards,
Kuba

Kuba Raczkowski

unread,
Dec 15, 2017, 10:33:36 AM12/15/17
to pyqtgraph
Ok, well, managed to do it based on https://stackoverflow.com/questions/4763992/finding-out-what-portion-of-a-qgraphicsitem-is-visible-in-a-qgraphicsview#

FYI, this gives a visible rectangle inside an imageitem, in its coordinates:

            view = self.getViewBox().getViewWidget()
            portRect = view.viewport().rect()
            sceneRect = view.mapToScene(portRect).boundingRect()
            itemRect = self.mapRectFromScene(sceneRect)
            isec = itemRect.intersected(self.boundingRect())


Kuba

Luke Campagnola

unread,
Dec 20, 2017, 1:02:08 AM12/20/17
to pyqt...@googlegroups.com
In the past I have used QGraphicsTextItem with a monospace font for displaying grids of characters.
That should yield good performance, depending on the size of your image.

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/8a620fae-e972-4761-89da-25bf2490d095%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Kuba

unread,
Dec 20, 2017, 2:45:03 AM12/20/17
to pyqt...@googlegroups.com
Thanks for reply Luc! 
Any thoughs on whether using QGraphicsTextItem would be preferable to modifying the paint() of ImageItem?

Kuba

--
You received this message because you are subscribed to a topic in the Google Groups "pyqtgraph" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pyqtgraph/vR8t4JAlhVA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pyqtgraph+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/CACZXET9QCrUQEnNWE_c5nksYBug2OQ_vcdKUnr8t%3D7aVQsr7SA%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages