retuve.hip_xray.draw
Drawing code related to hip xray images.
1# Copyright 2024 Adam McArthur 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15""" 16Drawing code related to hip xray images. 17""" 18 19import time 20from typing import List 21 22from numpy.typing import NDArray 23 24from retuve.classes.draw import Overlay 25from retuve.classes.seg import SegFrameObjects 26from retuve.draw import draw_landmarks, resize_data_for_display 27from retuve.hip_xray.classes import HipDataXray 28from retuve.hip_xray.metrics.ace import draw_ace 29from retuve.keyphrases.config import Config 30from retuve.logs import log_timings 31 32 33def draw_hips_xray( 34 hip_datas: List[HipDataXray], 35 results: List[SegFrameObjects], 36 config: Config, 37) -> List[NDArray]: 38 """ 39 Draw the hip xray images 40 41 :param hip_datas: The Hip Datas 42 :param results: The Segmentation Results 43 :param config: The Config 44 45 :return: The Drawn Images as Numpy Arrays 46 """ 47 draw_timings = [] 48 image_arrays = [] 49 50 for hip, seg_frame_objs in zip(hip_datas, results): 51 start = time.time() 52 53 final_hip, final_seg_frame_objs, final_image = resize_data_for_display( 54 hip, seg_frame_objs 55 ) 56 57 overlay = Overlay( 58 (final_image.shape[0], final_image.shape[1], 3), config 59 ) 60 61 # overlay = draw_seg(final_seg_frame_objs, overlay, config) 62 63 overlay = draw_landmarks(final_hip, overlay) 64 65 overlay = draw_ace(final_hip, overlay, config) 66 67 img = overlay.apply_to_image(final_image) 68 69 image_arrays.append(img) 70 draw_timings.append(time.time() - start) 71 72 log_timings(draw_timings, title="Drawing Speed:") 73 74 return image_arrays
def
draw_hips_xray( hip_datas: List[retuve.hip_xray.classes.HipDataXray], results: List[retuve.classes.seg.SegFrameObjects], config: retuve.keyphrases.config.Config) -> List[numpy.ndarray[Any, numpy.dtype[+_ScalarType_co]]]:
34def draw_hips_xray( 35 hip_datas: List[HipDataXray], 36 results: List[SegFrameObjects], 37 config: Config, 38) -> List[NDArray]: 39 """ 40 Draw the hip xray images 41 42 :param hip_datas: The Hip Datas 43 :param results: The Segmentation Results 44 :param config: The Config 45 46 :return: The Drawn Images as Numpy Arrays 47 """ 48 draw_timings = [] 49 image_arrays = [] 50 51 for hip, seg_frame_objs in zip(hip_datas, results): 52 start = time.time() 53 54 final_hip, final_seg_frame_objs, final_image = resize_data_for_display( 55 hip, seg_frame_objs 56 ) 57 58 overlay = Overlay( 59 (final_image.shape[0], final_image.shape[1], 3), config 60 ) 61 62 # overlay = draw_seg(final_seg_frame_objs, overlay, config) 63 64 overlay = draw_landmarks(final_hip, overlay) 65 66 overlay = draw_ace(final_hip, overlay, config) 67 68 img = overlay.apply_to_image(final_image) 69 70 image_arrays.append(img) 71 draw_timings.append(time.time() - start) 72 73 log_timings(draw_timings, title="Drawing Speed:") 74 75 return image_arrays
Draw the hip xray images
Parameters
- hip_datas: The Hip Datas
- results: The Segmentation Results
- config: The Config
Returns
The Drawn Images as Numpy Arrays