Commit e51053b1 authored by Edward Andò's avatar Edward Andò
Browse files

[skip-ci] safety in visual clients file name guessing, input parameters for...

[skip-ci] safety in visual clients file name guessing, input parameters for ereg and sketch of new DIC practice doc
parent acf1ce36
Pipeline #60774 skipped
......@@ -4,6 +4,34 @@
Tutorial: Image correlation -- Practice
****************************************
This is a general tutorial for doing image correlation: if your objective is to measure a displacement field with regularly-spacing points you're in the right place!
If you have discrete grains and you want to do particle tracking, read the "alignment" part of the tutorial, then go here: :ref:`discreteImageCorrelationTutorial`
Binning with illustration of how far to go
REMEMBER FOR register() to work you need to get your points close to the right transformation to be able to optimise
< flow chart >
When do you need alignment by eye? When it looks like this -> ROB
When do you need registration? When you have a clear and smoothly varing deformation like this -> NOT A SHEAR BAND!!
---------
OK let's define how to do the local part (copy from scripts page):
When do you need pixel search? When the initial guess from above is too rough introduce GLT GHT (copy from scripts page)
LDIC tricks, return status, etc...
********************
OLD VERSION
********************
Manipulating Φ
==========================
......
......@@ -24,47 +24,47 @@ from PyQt5.QtWidgets import QApplication, QWidget, QFileDialog, QGridLayout
import spam.visual.visualClass as visual
import numpy
import tifffile
import spam.helpers
def main():
app = QApplication(sys.argv)
# load parameters from sys.argv and if none have been called open a file manager to select them
try:
binning = int(sys.argv[1])
except:
print("usage : spam-ereg BINNING [Im1 Im2 Phi]")
print("binning = 1")
binning = 1
try:
fileName1 = sys.argv[2]
fileName2 = sys.argv[3]
images = [tifffile.imread(fileName1), tifffile.imread(fileName2)]
except:
Phi = numpy.eye(4)
if len(sys.argv) == 1:
# do the windows
images = []
fileName1 = QFileDialog.getOpenFileName(None, 'Open Image 1', os.getcwd())[0]
images.append(tifffile.imread(fileName1))
print(fileName1)
print(os.path.splitext(os.path.basename(fileName1)))
fileName2 = QFileDialog.getOpenFileName(None, 'Open Image 2', os.path.dirname(os.path.realpath(fileName1)))[0]
images.append(tifffile.imread(fileName2))
#f = QFileDialog.getOpenFileName(None, '(optional) Open Phi TSV', os.path.dirname(os.path.realpath(fileName1)))[0]
#if os.path.isfile(f):
#Phi = spam.helpers.readCorrelationTSV(f)['PhiField'][0]
elif len(sys.argv) == 3:
fileName1 = sys.argv[1]
fileName2 = sys.argv[2]
images = [tifffile.imread(fileName1), tifffile.imread(fileName2)]
elif len(sys.argv) == 4:
fileName1 = sys.argv[1]
fileName2 = sys.argv[2]
images = [tifffile.imread(fileName1), tifffile.imread(fileName2)]
Phi = spam.helpers.readCorrelationTSV(sys.argv[3])['PhiField'][0]
else:
print("usage:")
print(" - spam-ereg (by itself to have a popup window to select files)")
print(" - spam-ereg /path/to/Im1.tif /path/to/Im2.tif")
print(" - spam-ereg /path/to/Im1.tif /path/to/Im2.tif /path/to/PhiFile.tsv")
try:
f = numpy.genfromtxt(sys.argv[4], delimiter="\t", names=True)
Phi = numpy.array([[float(f["Fzz"]), float(f["Fzy"] ), float(f["Fzx"]), float(f['Zdisp'])],
[float(f["Fyz"]), float(f["Fyy"]), float(f["Fyx"]), float(f['Ydisp'])],
[float(f["Fxz"]), float(f["Fxy"]), float(f["Fxx"]), float(f['Xdisp'])],
[0, 0, 0, 1]])
except:
try:
f = numpy.genfromtxt(QFileDialog.getOpenFileName(None, '(optional) Open Phi TSV', os.path.dirname(os.path.realpath(fileName1)))[0], delimiter="\t", names=True)
Phi = numpy.array([[float(f["Fzz"]), float(f["Fzy"]), float(f["Fzx"]), float(f['Zdisp'])],
[float(f["Fyz"]), float(f["Fyy"]), float(f["Fyx"]), float(f['Ydisp'])],
[float(f["Fxz"]), float(f["Fxy"]), float(f["Fxx"]), float(f['Xdisp'])],
[0, 0, 0, 1]])
except:
Phi = numpy.eye(4, 4)
window = QWidget()
mainWindowGrid = QGridLayout(window)
eregWidget = visual.ereg(images, Phi, binning, [fileName1, fileName2])
eregWidget = visual.ereg(images, Phi, [fileName1, fileName2], binning=None)
mainWindowGrid.addWidget(eregWidget, 1, 1)
window.show()
eregWidget.show()
......
......@@ -154,7 +154,7 @@ class MainWindow(QWidget):
self.listOfBinning.addItems([str(b) for b in bins])
for i, b in enumerate(bins):
if "bin{}".format(b) in imName.lower().replace('-', '').replace('_', ''):
print('[SPAM MMR] From {}, I\'m guessing you work at bin level {}.'.format(imName, b))
print('[SPAM MMR] From {}, I\'m guessing you work at bin level {}.'.format(imName, b))
self.listOfBinning.setCurrentIndex(i)
grid.addWidget(self.listOfBinning, 6, 3, 1, 1)
......@@ -364,9 +364,9 @@ class MainWindow(QWidget):
passImages = [numpy.copy(self.images[0]), numpy.copy(self.images[1])]
self.eregWidget = visual.ereg(passImages,
self.Phi,
self.binning,
[os.path.basename(self.fileName1), os.path.basename(self.fileName2)],
imUpdate)
binning=self.binning,
imUpdate=imUpdate)
self.mainWindowGrid.addWidget(self.eregWidget, 1, 1)
self.startEregButton.close()
self.endEregButton = QPushButton("Next Step (Cropping)", self)
......@@ -381,9 +381,9 @@ class MainWindow(QWidget):
self.cropWidget = visual.QtCropWidget(passImages,
self.Phi,
self.crop,
self.binning,
[os.path.basename(self.fileName1), os.path.basename(self.fileName2)],
imUpdate)
binning=self.binning,
imUpdate=imUpdate)
self.mainWindowGrid.addWidget(self.cropWidget, 1, 1, 1, 2)
self.returnEregButton = QPushButton("Back (Eye Registration)")
self.returnEregButton.clicked.connect(self.backEreg)
......@@ -400,9 +400,9 @@ class MainWindow(QWidget):
passImages = [numpy.copy(self.images[0]), numpy.copy(self.images[1])]
self.eregWidget = visual.ereg(passImages,
self.Phi,
self.binning,
[os.path.basename(self.fileName1), os.path.basename(self.fileName2)],
imUpdate)
binning=self.binning,
imUpdate=imUpdate)
self.mainWindowGrid.addWidget(self.eregWidget, 1, 1)
self.endEregButton = QPushButton("Next Step (Cropping)", self)
self.endEregButton.clicked.connect(self.endEreg)
......
......@@ -315,7 +315,7 @@ def ldicParser(parser):
args.HWS[0] = 0
args.MARGIN[0] = 0
# Behaviour undefined for series run and im1 mask since im1 will change, complain and continue
if args.MASK1 is not None and args.SERIES_INCREMENTAL:
print("#############################################################")
......@@ -337,6 +337,8 @@ def ldicParser(parser):
#if args.SERIES_PHIFILE:
#args.TSV = True
# Nor prefix here because LDIC can still do an image series and needs to update the name
return args
......
......@@ -21,6 +21,7 @@ from __future__ import print_function
# system
import os
import os.path
# pyQt
from PyQt5 import QtCore
......@@ -56,7 +57,7 @@ cmapPhases = 'Set1_r'
class ereg(QWidget):
def __init__(self, _images, enterPhi, binning, names, imUpdate=0):
def __init__(self, _images, enterPhi, names, binning=None, imUpdate=0):
# init every graphical widget and create all the variables that will be used
QWidget.__init__(self)
......@@ -280,7 +281,11 @@ class ereg(QWidget):
self.minusRadioButton.setChecked(True)
self.minusAbsRadioButton.setChecked(False)
self.CBRadioButton.setChecked(False)
self.nameEntry = QLineEdit("{}-{}-PhiEye-bin{}.tsv".format(names[0][0:-4], names[1][0:-4], self.binning))
if self.binning is None:
self.nameEntry = QLineEdit("{}-{}-PhiEye.tsv".format(os.path.splitext(os.path.basename(names[0]))[0], os.path.splitext(os.path.basename(names[1]))[0]))
else:
self.nameEntry = QLineEdit("{}-{}-PhiEye-bin{}.tsv".format(os.path.splitext(os.path.basename(names[0]))[0], os.path.splitext(os.path.basename(names[1]))[0], self.binning))
self.saveButton = QPushButton("Save")
self.resultLabel = QLabel()
......@@ -954,13 +959,21 @@ class ereg(QWidget):
fileName = tmp if tmp.split(".")[-1] in ["tsv"] else tmp + ".tsv"
# save.writeRegistrationTSV(fileName, (numpy.array(self.images[1].shape) - 1) / 2.0, {
# 'PhiCentre': self.Phis[1], "returnStatus": 2, "iterations": self.iterations, "error": 100, "deltaPhiNorm": 0.1})
TSVheader = "Zpos\tYpos\tXpos\tFzz\tFzy\tFzx\tZdisp\tFyz\tFyy\tFyx\tYdisp\tFxz\tFxy\tFxx\tXdisp\tbin\treturnStatus\tdeltaPhiNorm\terror\titerations"
centre = (numpy.array(self.images[0].shape)-1)/2.0
output = numpy.array([[centre[0]], [centre[1]], [centre[2]],
[self.Phis[1][0, 0]], [self.Phis[1][0, 1]], [self.Phis[1][0, 2]], [self.Phis[1][0, 3]],
[self.Phis[1][1, 0]], [self.Phis[1][1, 1]], [self.Phis[1][1, 2]], [self.Phis[1][1, 3]],
[self.Phis[1][2, 0]], [self.Phis[1][2, 1]], [self.Phis[1][2, 2]], [self.Phis[1][2, 3]],
[self.binning], [0], [1.0], [self.images[0].mean()], [0] ])
if self.binning is None:
TSVheader = "Zpos\tYpos\tXpos\tFzz\tFzy\tFzx\tZdisp\tFyz\tFyy\tFyx\tYdisp\tFxz\tFxy\tFxx\tXdisp\treturnStatus\tdeltaPhiNorm\terror\titerations"
output = numpy.array([[centre[0]], [centre[1]], [centre[2]],
[self.Phis[1][0, 0]], [self.Phis[1][0, 1]], [self.Phis[1][0, 2]], [self.Phis[1][0, 3]],
[self.Phis[1][1, 0]], [self.Phis[1][1, 1]], [self.Phis[1][1, 2]], [self.Phis[1][1, 3]],
[self.Phis[1][2, 0]], [self.Phis[1][2, 1]], [self.Phis[1][2, 2]], [self.Phis[1][2, 3]],
[0], [1.0], [self.images[0].mean()], [0] ])
else:
TSVheader = "Zpos\tYpos\tXpos\tFzz\tFzy\tFzx\tZdisp\tFyz\tFyy\tFyx\tYdisp\tFxz\tFxy\tFxx\tXdisp\treturnStatus\tdeltaPhiNorm\terror\titerations\tbin"
output = numpy.array([[centre[0]], [centre[1]], [centre[2]],
[self.Phis[1][0, 0]], [self.Phis[1][0, 1]], [self.Phis[1][0, 2]], [self.Phis[1][0, 3]],
[self.Phis[1][1, 0]], [self.Phis[1][1, 1]], [self.Phis[1][1, 2]], [self.Phis[1][1, 3]],
[self.Phis[1][2, 0]], [self.Phis[1][2, 1]], [self.Phis[1][2, 2]], [self.Phis[1][2, 3]],
[0], [1.0], [self.images[0].mean()], [0], [self.binning] ])
numpy.savetxt(fileName, output.T, fmt='%.7f', delimiter='\t', newline='\n', comments='', header=TSVheader)
self.resultLabel.setText("Phi saved in: {}".format(os.path.join(os.getcwd(), fileName)))
self.resultLabel.setStyleSheet("QLabel {font-weight: bold; color: green;}")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment