From 73629cfeaaabba2ffbc2baef886433a1027be6f4 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Jacob <137695414+jbjacob94@users.noreply.github.com> Date: Tue, 31 Oct 2023 09:00:43 +0100 Subject: [PATCH 1/3] added a new method to blobcorrector.correctorclass to do distorsion correction using a pixel LUT --- ImageD11/blobcorrector.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/ImageD11/blobcorrector.py b/ImageD11/blobcorrector.py index 387f3b1c..9a625a89 100644 --- a/ImageD11/blobcorrector.py +++ b/ImageD11/blobcorrector.py @@ -71,6 +71,7 @@ def __init__(self, argsplinefile, orientation="edf"): self.gridspacing = 0.0 self.tck1 = None self.tck2 = None + self.dim = (2048,2048) # Detector dimensions (needed for correct_px_lut method). this should work for frelon cameras. Needs to be modified for other types of detectors if self.splinefile is not None: self.readfit2dspline(self.splinefile) @@ -138,6 +139,34 @@ def make_pos_lut(self, dims): self.pixel_lut[1] * self.ysize ) return self.pos_lut + + def correct_px_lut(self, pks): + """Transform x,y in raw image coordinates into x,y of an + idealised image using a LUT. Faster than standard correct method for large peakfiles. + pks : ImageD11 columnfile with raw coordinates s_raw, f_raw + add new colulmns sc, fc with corrected coordinates""" + + assert self.dim is not None + assert 's_raw' in pks.titles and f_raw in pks.titles + + # make pixel_lut + substract xy grid coordinate (i,j) to keep only dx and dy arrays. + self.make_pixel_lut(self.dim) + i,j = numpy.mgrid[ 0:self.dim[0], 0:self.dim[1] ] + dx = self.pixel_lut[0] - i + dy = self.pixel_lut[1] - j + + # get integer pixel index (si,fi) of each peak + si = np.round(pks['s_raw']).astype(int) + fi = np.round(pks['f_raw']).astype(int) + + # apply dx dy correction on s_raw / f_raw + sc = (dx[ si, fi ] + pks.s_raw).astype(np.float32) + fc = (dy[ si, fi ] + pks.f_raw).astype(np.float32) + # add corrected arrays as new columns + pks.addcolumn(sc, 'sc') + pks.addcolumn(fc, 'fc') + + def distort(self, xin, yin): """ Distort a pair of points xnew, ynew to find where they From ac2b68396d92bc93ccb0022b74cd40eda98fb766 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Jacob <137695414+jbjacob94@users.noreply.github.com> Date: Tue, 31 Oct 2023 11:50:21 +0100 Subject: [PATCH 2/3] Update blobcorrector.py Added new property self.dim with detector dimension to blobcorrector.correctorclass, inferred from the splinefile (xmin, xmax, ymin, ymax) --- ImageD11/blobcorrector.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ImageD11/blobcorrector.py b/ImageD11/blobcorrector.py index 9a625a89..011ce21e 100644 --- a/ImageD11/blobcorrector.py +++ b/ImageD11/blobcorrector.py @@ -71,10 +71,9 @@ def __init__(self, argsplinefile, orientation="edf"): self.gridspacing = 0.0 self.tck1 = None self.tck2 = None - self.dim = (2048,2048) # Detector dimensions (needed for correct_px_lut method). this should work for frelon cameras. Needs to be modified for other types of detectors if self.splinefile is not None: self.readfit2dspline(self.splinefile) - + self.dim = (self.xmax-self.xmin, self.ymax-self.ymin) # detector dimensions read from splinefile def correct(self, xin, yin): From aee79f1091f116050c40607357e53883dbeabaa6 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Jacob <137695414+jbjacob94@users.noreply.github.com> Date: Tue, 31 Oct 2023 15:36:47 +0100 Subject: [PATCH 3/3] Update blobcorrector.py --- ImageD11/blobcorrector.py | 42 +++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/ImageD11/blobcorrector.py b/ImageD11/blobcorrector.py index 011ce21e..1c21575c 100644 --- a/ImageD11/blobcorrector.py +++ b/ImageD11/blobcorrector.py @@ -73,7 +73,7 @@ def __init__(self, argsplinefile, orientation="edf"): self.tck2 = None if self.splinefile is not None: self.readfit2dspline(self.splinefile) - self.dim = (self.xmax-self.xmin, self.ymax-self.ymin) # detector dimensions read from splinefile + self.dim = ( int(self.xmax-self.xmin), int(self.ymax-self.ymin)) # detector dimensions read from splinefile def correct(self, xin, yin): @@ -140,31 +140,30 @@ def make_pos_lut(self, dims): def correct_px_lut(self, pks): - """Transform x,y in raw image coordinates into x,y of an + """Transform x,y in raw image coordinates into x,y of an idealised image using a LUT. Faster than standard correct method for large peakfiles. - pks : ImageD11 columnfile with raw coordinates s_raw, f_raw - add new colulmns sc, fc with corrected coordinates""" + pks : ImageD11 columnfile with raw coordinates s_raw, f_raw add new colulmns sc, fc with corrected coordinates""" - assert self.dim is not None - assert 's_raw' in pks.titles and f_raw in pks.titles - - # make pixel_lut + substract xy grid coordinate (i,j) to keep only dx and dy arrays. - self.make_pixel_lut(self.dim) - i,j = numpy.mgrid[ 0:self.dim[0], 0:self.dim[1] ] - dx = self.pixel_lut[0] - i - dy = self.pixel_lut[1] - j - - # get integer pixel index (si,fi) of each peak - si = np.round(pks['s_raw']).astype(int) - fi = np.round(pks['f_raw']).astype(int) - - # apply dx dy correction on s_raw / f_raw - sc = (dx[ si, fi ] + pks.s_raw).astype(np.float32) - fc = (dy[ si, fi ] + pks.f_raw).astype(np.float32) + assert self.dim is not None + assert 's_raw' in pks.titles and 'f_raw' in pks.titles + + # make pixel_lut + substract xy grid coordinate (i,j) to keep only dx and dy arrays. + self.make_pixel_lut(self.dim) + i,j = numpy.mgrid[ 0:self.dim[0], 0:self.dim[1] ] + dx = self.pixel_lut[0] - i + dy = self.pixel_lut[1] - j + + # get integer pixel index (si,fi) of each peak + si = numpy.round(pks['s_raw']).astype(int) + fi = numpy.round(pks['f_raw']).astype(int) + + # apply dx dy correction on s_raw / f_raw + sc = (dx[ si, fi ] + pks.s_raw).astype(numpy.float32) + fc = (dy[ si, fi ] + pks.f_raw).astype(numpy.float32) # add corrected arrays as new columns pks.addcolumn(sc, 'sc') pks.addcolumn(fc, 'fc') - + def distort(self, xin, yin): """ @@ -366,4 +365,3 @@ def pixel_lut(self): # Hence, for now, # """ # pass -