From 2b753cfcc4cd22d43addce83f70aa9543129baca Mon Sep 17 00:00:00 2001 From: Sandip Samal Date: Tue, 27 Aug 2024 16:39:24 -0400 Subject: [PATCH] remove aspect and DPI calculations --- markimg/markimg.py | 26 ++++++++++++-------------- requirements.txt | 1 + 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/markimg/markimg.py b/markimg/markimg.py index 699f01c..e4d4e9e 100644 --- a/markimg/markimg.py +++ b/markimg/markimg.py @@ -13,7 +13,7 @@ import math import os import sys - +from PIL import Image import cv2 import matplotlib import matplotlib.pyplot as plt @@ -21,6 +21,7 @@ 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 @@ -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 @@ -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} diff --git a/requirements.txt b/requirements.txt index 4ab442d..076f73c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,4 +6,5 @@ loguru pftag==1.2.22 pflog==1.2.26 pftel-client +pillow