From 2e6bc1c87ef1c356cfbb9b73c5a5df3c5668122f Mon Sep 17 00:00:00 2001 From: Samarth Shetty Date: Fri, 28 Jun 2024 20:55:15 -0400 Subject: [PATCH] add get_window_coord1 to functions --- functions/get_wind_coord1.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 functions/get_wind_coord1.py diff --git a/functions/get_wind_coord1.py b/functions/get_wind_coord1.py new file mode 100644 index 0000000..bdcc5ad --- /dev/null +++ b/functions/get_wind_coord1.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Wed Jun 26 11:42:57 2024 + +@author: samarth +""" + +import numpy as np +from skimage.measure import regionprops + +def get_wind_coord1(Ihere, cell_margin): + x_size, y_size = Ihere.shape + + if np.sum(Ihere) > 0: # not empty object + s_f = regionprops(Ihere) + if s_f: # not empty + bbox = np.round(s_f[0].bbox).astype(int) + lower_x_limit = max(0, bbox[1] - cell_margin) + upper_x_limit = min(y_size, bbox[3] + cell_margin) + lower_y_limit = max(0, bbox[0] - cell_margin) + upper_y_limit = min(x_size, bbox[2] + cell_margin) + x_cn = np.arange(lower_x_limit, upper_x_limit) + y_cn = np.arange(lower_y_limit, upper_y_limit) + else: + print('empty or multiple object given - error') + x_cn, y_cn = None, None + else: + x_cn = np.arange(y_size) + y_cn = np.arange(x_size) + + return x_cn, y_cn