Skip to content

Commit

Permalink
add options to save as jpg or png
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandip117 committed Aug 28, 2024
1 parent 2b753cf commit bd0686d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
24 changes: 17 additions & 7 deletions markimg/markimg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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)
Expand Down Expand Up @@ -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}

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit bd0686d

Please sign in to comment.