Pytorch tensor put z values with x & y coordinates into grid

Viewed 249

I'm having a torch tensor of shape [3,N], where the three dimensions correspond to x,y,z values, respectively, and N is the number of data points. I.e., the tensor looks like this:

[x1, y1, z1]
[x2, y2, z2]
    ...
[xN, yN, zN]

The x&y values of the tensor correspond to x&y coordinates in an image, while the z value corresponds to the brightness at position [x,y]. Now what I want to do, is to reconstruct the image, based on the values of the tensor.

Normally, I do this with torch.tensor.put_ (Pytorch Reference).

The problem is, some x&y combinations appear multiple times in the image, i.e. I have multiple color values for a position [x,y], and I only want to keep the highest z-value at each position.

For example, lets take a 2x2 image. The tensor could then look like this:

[0,0,1]
[0,0,3]
[0,1,0]
[1,0,1]
[1,1,1]
[1,1,3]
[1,1,5]

And the desired output would then be

y
^
|  [0, 5]
|  [3, 1]
|
--------> x

Does anyone know how I could achieve this without iterating over all datapoints N, similar to the torch.tensor.put_ method?

0 Answers
Related