Coverage for modules/XRayViewer.py: 31%
32 statements
« prev ^ index » next coverage.py v7.0.4, created at 2023-01-10 09:27 -0600
« prev ^ index » next coverage.py v7.0.4, created at 2023-01-10 09:27 -0600
1"""
2Copyright 1999 Illinois Institute of Technology
4Permission is hereby granted, free of charge, to any person obtaining
5a copy of this software and associated documentation files (the
6"Software"), to deal in the Software without restriction, including
7without limitation the rights to use, copy, modify, merge, publish,
8distribute, sublicense, and/or sell copies of the Software, and to
9permit persons to whom the Software is furnished to do so, subject to
10the following conditions:
12The above copyright notice and this permission notice shall be
13included in all copies or substantial portions of the Software.
15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18IN NO EVENT SHALL ILLINOIS INSTITUTE OF TECHNOLOGY BE LIABLE FOR ANY
19CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23Except as contained in this notice, the name of Illinois Institute
24of Technology shall not be used in advertising or otherwise to promote
25the sale, use or other dealings in this Software without prior written
26authorization from Illinois Institute of Technology.
27"""
29import fabio
30import numpy as np
31try:
32 from ..utils.file_manager import fullPath, ifHdfReadConvertless
33 from ..utils.image_processor import *
34except: # for coverage
35 from utils.file_manager import fullPath, ifHdfReadConvertless
36 from utils.image_processor import *
38class XRayViewer:
39 """
40 A class for Quadrant Folding processing - go to process() to see all processing steps
41 """
42 def __init__(self, img_path, img_name, file_list=None, extension=''):
43 """
44 Initial value for QuadrantFolder object
45 :param img_path: directory path of input image
46 :param img_name: image file name
47 """
48 self.img_name = img_name
49 if extension in ('.hdf5', '.h5'):
50 index = next((i for i, item in enumerate(file_list[0]) if item == img_name), 0)
51 self.orig_img = file_list[1][index]
52 else:
53 self.orig_img = fabio.open(fullPath(img_path, img_name)).data
54 self.orig_img = ifHdfReadConvertless(img_name, self.orig_img)
55 self.orig_img = self.orig_img.astype("float32")
56 self.orig_image_center = None
57 self.hist = []
58 self.dl, self.db = 0, 0
59 if self.orig_img.shape == (1043, 981):
60 self.img_type = "PILATUS"
61 else:
62 self.img_type = "NORMAL"
64 def getRotatedImage(self, angle, center):
65 """
66 Get rotated image by angle while image = original input image, and angle = self.info["rotationAngle"]
67 """
68 img = np.array(self.orig_img, dtype="float32")
69 b, l = img.shape
70 rotImg, _, _ = rotateImage(img, center, angle, self.img_type, -999)
72 # Cropping off the surrounding part since we had already expanded the image to maximum possible extent in centerize image
73 bnew, lnew = rotImg.shape
74 db, dl = (bnew - b)//2, (lnew-l)//2
75 final_rotImg = rotImg[db:bnew-db, dl:lnew-dl]
76 self.dl, self.db = dl, db # storing the cropped off section to recalculate coordinates when manual center is given
78 return final_rotImg