Solved Matching 2 .tiff images pixel-by-pixel
-
Hello, I am trying to build a PyQt application that takes as input two .tiff UAV images files and outputs another .tiff UAV image file after some processing. The two input UAV images represent the same geographical location but they are not captured from the same angle. What I want to do is let's say I want to process the pixel (at LON/LAT:10000, 20000) from the 1st UAV image with the pixel (at LON/LAT:10000, 20000) pixel from the 2nd UAV image, do some calculations and output another UAV image .tiff file. How do I match the 2 images?
-
Hi,
For the image processing part, you should check OpenCV.
-
This post is deleted! -
Check with the tifffile project.
-
I don't know if I need to open a new thread, but in the .tif image I open, how to I specify with a rectangle the area I want to process? I do not want to put the rectangle a priori, but in "real time" as I examine the image and to help my code do process on the specific space bounded by the rectangle....
-
QRubberBand comes to mind.
-
This post is deleted! -
I use this code: https://stackoverflow.com/questions/13840289/how-to-use-qrubberband-with-qrect-class-in-pyqt
inside my widget, more specifically, this code:def mousePressEvent(self, event): self.origin = event.pos() self.rubberband.setGeometry( QtCore.QRect(self.origin, QtCore.QSize())) self.rubberband.show() QtGui.QWidget.mousePressEvent(self, event) def mouseMoveEvent(self, event): if self.rubberband.isVisible(): self.rubberband.setGeometry( QtCore.QRect(self.origin, event.pos()).normalized()) QtGui.QWidget.mouseMoveEvent(self, event) def mouseReleaseEvent(self, event): if self.rubberband.isVisible(): self.rubberband.hide() selected = [] rect = self.rubberband.geometry() for child in self.findChildren(QtGui.QPushButton): if rect.intersects(child.geometry()): selected.append(child) print 'Selection Contains:\n ', if selected: print ' '.join( 'Button: %s\n' % child.text() for child in selected) else: print ' Nothing\n' QtGui.QWidget.mouseReleaseEvent(self, event)
but I don't see any rectangle...
-
Are you sure your methods are called ?
-
I use these method calls:
self.mousePressEvent() self.mouseMoveEvent() self.mouseReleaseEvent()
inside the main widget class..but what do I put inside the parenthesis? Because "event" does not seem to work...
-
@john_hobbyist
What do you mean by "I use these method calls"? These methods are supposed to be overrides. Qt infrastructure calls them when it detects the mouse event, with the appropriateevent
parameter.And anyway @SGaist was asking you put a debugging
print()
statement inside these override methods to make sure they are getting called. -
I am trying some ready examples in order to understand the rationale. I run the first code from here: https://stackoverflow.com/questions/34220275/how-to-select-a-region-with-qrubberband-on-a-qlabel-like-in-ksnapshot
I have changed PyQt4 ---> PyQt5 and QtGui ----> QtWidgets. I also changed this line:
pixmap = QPixmap.grabWindow(app.desktop().winId())
with this:
pixmap = QScreen.grabWindow(app.desktop().winId())
but I get this error:
File "QRubberBandonaQLabelKSnapshot.py", line 47, in initUI pixmap = QScreen.grabWindow(app.desktop().winId()) TypeError: grabWindow(self, sip.voidptr, x: int = 0, y: int = 0, width: int = -1, height: int = -1): first argument of unbound method must have type 'QScreen'
Any idea what to do here?
-
You're using it as if it were a static method which it's not. You need an instance of QScreen.
You can get one from your QApplication.
-
@SGaist Sorry I do not understand...how I get an instance from QApplication in QScreen?
-
It's the other way around.
In any case, you should rather get the screen from your widget.
Take a look at the screenshot example.
-
I just try to see how to run the QRubberBand in PyQt5....
-
Did you check the example from the class documentation ?
-
I added them to the main class. I am trying to call the methods, like this:
self.mousePressEvent(event) self.mouseMoveEvent(event)
etc.
But what do I put inside/instead of "event"?
-
The code you showed higher up to drive the rubber band.
Or the docs @SGaist points to. they explain in detail what is needed.def mousePressEvent(self, event): ///// this set the start location of the band self.origin = event.pos() self.rubberband.setGeometry( QtCore.QRect(self.origin, QtCore.QSize())) self.rubberband.show() QtGui.QWidget.mousePressEvent(self, event) def mouseMoveEvent(self, event): // this makes the band follow the mouse to adjust the size if self.rubberband.isVisible(): self.rubberband.setGeometry( QtCore.QRect(self.origin, event.pos()).normalized()) QtGui.QWidget.mouseMoveEvent(self, event) def mouseReleaseEvent(self, event): // this is the end of the operation and you use the rectange defined by the band if self.rubberband.isVisible(): self.rubberband.hide() rect = self.rubberband.geometry() ... then use rect for whatever you need
-
@mrjj: Thanks for your help! I am searching all morning. Here https://doc.qt.io/qtforpython/PySide6/QtWidgets/QRubberBand.html#more I don't see something about what to put inside the "event". The only I can understand is to use this inside events: https://doc.qt.io/qtforpython-5/PySide2/QtGui/QMouseEvent.html