I’m trying to figure out the Tensor math to set an imagepoint to be upper left corner when either part of the point position is greater than 1 or less than -1.
The default ImagePoint behavior is to drop the point when the position falls outside of the image, i.e. center cut or other transformations cause the point to be outside the images.
I was thinking about creating a subclass of ImagePoint and replace the _remove_points_out function call with _upper_left_points function. The order of the points matters in my domain. Dropping points loses the positional relationships. So something like:
“Support applying transforms to a
flow of ordered key coordinates.”
def init(self, flow:FlowField, scale:bool=True, y_first:bool=True):
super().init(flow, scale, y_first)
@property def data(self)->Tensor: "Return the points associated to this object." flow = self.flow #This updates flow before we test if some transforms happened if self.transformed: flow = _upper_left_points(flow) self.transformed=False return flow.flow.flip(1)
The goal would be to change both coordinates when one is outside the image.
flow2 = torch.where(flow.flow < -1, y, flow.flow)
only replaces the coordinate outside the image.
for row in flow.flow.split(1): might be able to iterate over each point and identify clauses that change the row coordinates. This seems like it wouldn't be that efficient. On the other hand, it should be a batch focused function call.
Other ideas would be to treat each point as having a class, and retain the logic to drop points out of image
Any other ideas?