# Untitled

unknown

plain_text

a year ago

1.4 kB

2

Indexable

Never

^{}

import numpy as np def scale_polygons(polygons, original_size, new_size): """ Scales a list of polygons to a new size. Parameters: - polygons: a list of polygons, where each polygon is a list of points - original_size: the size of the original image as a tuple (height, width) - new_size: the desired size of the new image as a tuple (height, width) Returns: - a list of scaled polygons """ # Calculate the scale factor for each axis scale_x = new_size[1] / original_size[1] scale_y = new_size[0] / original_size[0] # Create an empty list to store the scaled polygons scaled_polygons = [] # Iterate through each polygon in the list for polygon in polygons: # Create an empty list to store the scaled points of the polygon scaled_polygon = [] # Iterate through each point in the polygon for point in polygon: # Scale the point using the scale factors scaled_point = [int(point[0] * scale_x), int(point[1] * scale_y)] # Append the scaled point to the scaled polygon scaled_polygon.append(scaled_point) # Append the scaled polygon to the list of scaled polygons scaled_polygons.append(scaled_polygon) return scaled_polygons