Skip to content

Commit

Permalink
remove aspect and DPI calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandip117 committed Aug 27, 2024
1 parent c4f2f4d commit 2b753cf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
26 changes: 12 additions & 14 deletions markimg/markimg.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
import math
import os
import sys

from PIL import Image
import cv2
import matplotlib
import matplotlib.pyplot as plt
from chrisapp.base import ChrisApp
from loguru import logger
from pflog import pflog
from markimg.imageCanvas import ImageCanvas
import numpy as np

matplotlib.rcParams['font.family'] = 'monospace'
LOG = logger.debug
Expand Down Expand Up @@ -415,10 +416,14 @@ def run(self, options):

LOG(f"Reading input image from {file_path[0]}")
image = cv2.imread(file_path[0])

plt.style.use('dark_background')
plt.axis('off')

max_y, max_x, max_z = image.shape
plt.figure(figsize=(max_x / 100, max_y / 100))
plt.imshow(image, aspect='auto')

img_XY_plane: ImageCanvas = ImageCanvas(max_y, max_x)
height = data[row]["origHeight"]
ht_scale = height / max_x
Expand Down Expand Up @@ -604,22 +609,15 @@ def run(self, options):
# Clean up all matplotlib stuff and save as PNG
plt.tick_params(left=False, right=False, labelleft=False,
labelbottom=False, bottom=False)
plt.savefig(os.path.join("/tmp", row + "img.jpg"), bbox_inches='tight', pad_inches=0.0)
plt.clf()

plt.imshow(image)
plt.savefig(os.path.join("/tmp", row + "img.png"), bbox_inches='tight', pad_inches=0.0)
tmppng = cv2.imread(os.path.join("/tmp", row + "img.png"))
y, x, z = tmppng.shape
dpi = (max_x / x) * 100
LOG(f"Input image dimensions {image.shape}")
LOG(f'Applying DPI {dpi} to the output image')
png = cv2.imread(os.path.join("/tmp", row + "img.jpg"))

plt.savefig(os.path.join("/tmp", row + ".png"), dpi=dpi, bbox_inches='tight', pad_inches=0.0)
plt.clf()
png = cv2.imread(os.path.join("/tmp", row + ".png"))
inverted_png = cv2.rotate(png, cv2.ROTATE_90_CLOCKWISE)

LOG(f"Output image dimensions {png.shape}")
cv2.imwrite(os.path.join(options.outputdir, row + ".png"), inverted_png)
LOG(f"Output image dimensions {image.shape}")
LOG(f"Output image dimensions {inverted_png.shape}")
cv2.imwrite(os.path.join(options.outputdir, row + ".jpg"), 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
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ loguru
pftag==1.2.22
pflog==1.2.26
pftel-client
pillow

0 comments on commit 2b753cf

Please sign in to comment.