From bd0686d9d6dc80a3f9c4e32391ba0b2cde677b95 Mon Sep 17 00:00:00 2001 From: "sandipsamal117@gmail.com" Date: Wed, 28 Aug 2024 10:33:29 -0400 Subject: [PATCH] add options to save as jpg or png --- markimg/markimg.py | 24 +++++++++++++++++------- setup.py | 2 +- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/markimg/markimg.py b/markimg/markimg.py index e4d4e9e..0d2fdc9 100644 --- a/markimg/markimg.py +++ b/markimg/markimg.py @@ -359,6 +359,13 @@ def define_parameters(self): optional=True, help='Offset of additional text on the final output,' 'default value is 0,0') + self.add_argument('--outputImageExtension', + dest='outputImageExtension', + default='jpg', + type=str, + optional=True, + help='Generated output image file extension,' + 'default value is jpg') def preamble_show(self, options) -> None: """ @@ -421,7 +428,7 @@ def run(self, options): plt.axis('off') max_y, max_x, max_z = image.shape - plt.figure(figsize=(max_x / 100, max_y / 100)) + plt.figure(figsize=(max_x / 100, max_y / 100)) plt.imshow(image, aspect='auto') img_XY_plane: ImageCanvas = ImageCanvas(max_y, max_x) @@ -509,7 +516,8 @@ def run(self, options): self.compareLength(d_lengths['Left femur'], d_lengths['Right femur']).split(':')[0] femurDiffText = 'Difference'.rjust(16) + f': {femurDiffInfo}' - d_femur['Difference'] = femurDiffInfo + self.compareLength(d_lengths['Left femur'], d_lengths['Right femur']).split(':')[1] + d_femur['Difference'] = femurDiffInfo + \ + self.compareLength(d_lengths['Left femur'], d_lengths['Right femur']).split(':')[1] x_pos = x_pos + line_gap plt.text(x_pos, y_pos, femurDiffText, color='white', fontsize=options.textSize, rotation=90) @@ -532,7 +540,8 @@ def run(self, options): self.compareLength(d_lengths['Left tibia'], d_lengths['Right tibia']).split(':')[0] tibaiDiffText = 'Difference'.rjust(16) + f': {tibiaDiffInfo}' - d_tibia['Difference'] = tibiaDiffInfo + self.compareLength(d_lengths['Left tibia'], d_lengths['Right tibia']).split(':')[1] + d_tibia['Difference'] = tibiaDiffInfo + \ + self.compareLength(d_lengths['Left tibia'], d_lengths['Right tibia']).split(':')[1] x_pos = x_pos + line_gap plt.text(x_pos, y_pos, tibaiDiffText, color='white', fontsize=options.textSize, rotation=90) @@ -541,13 +550,13 @@ def run(self, options): d_total = {} totalRightInfo = 'Total right'.rjust(16) + \ - f": {str(self.getSum(d_lengths['Right femur'], d_lengths['Right tibia']))} {unit}" + f": {str(self.getSum(d_lengths['Right femur'], d_lengths['Right tibia']))} {unit}" d_total['Total right'] = str(self.getSum(d_lengths['Right femur'], d_lengths['Right tibia'])) + f' {unit}' x_pos = x_pos + line_gap plt.text(x_pos, y_pos, totalRightInfo, color='white', fontsize=options.textSize, rotation=90) totalLeftInfo = 'Total left'.rjust(16) + \ - f": {str(self.getSum(d_lengths['Left femur'], d_lengths['Left tibia']))} {unit}" + f": {str(self.getSum(d_lengths['Left femur'], d_lengths['Left tibia']))} {unit}" d_total['Total left'] = str(self.getSum(d_lengths['Left femur'], d_lengths['Left tibia'])) + f' {unit}' x_pos = x_pos + line_gap plt.text(x_pos, y_pos, totalLeftInfo, color='white', fontsize=options.textSize, rotation=90) @@ -615,9 +624,10 @@ def run(self, options): png = cv2.imread(os.path.join("/tmp", row + "img.jpg")) inverted_png = cv2.rotate(png, cv2.ROTATE_90_CLOCKWISE) - LOG(f"Output image dimensions {image.shape}") + LOG(f"Input image dimensions {image.shape}") LOG(f"Output image dimensions {inverted_png.shape}") - cv2.imwrite(os.path.join(options.outputdir, row + ".jpg"), inverted_png) + cv2.imwrite(os.path.join(options.outputdir, row + f".{options.outputImageExtension}"), inverted_png) + d_json[row] = {'info': d_info, 'femur': d_femur, 'tibia': d_tibia, 'total': d_total, 'pixel_distance': d_pixel, 'details': details} diff --git a/setup.py b/setup.py index a48aa79..e1255c1 100755 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ setup( name='markimg', - version='1.5.4', + version='1.5.5', description='An app to mark landmark points and lines on an input image', long_description=readme, author='FNNDSC',