Hi Thomas,
thanks for your answer, I added some details on my code in order to be runnable, I hope this is understandable and detailed enough since it contains the principle of this method/problem.
import torch
import matplotlib.pyplot as plt

closed = torch.Tensor([0.,0.])
aperture = torch.Tensor([-100,100])
leafs = torch.cat([closed.repeat(30,1), aperture.repeat(20,1), closed.repeat(30,1)])

IMG_SIZE = (400,400)
IMG_RES = (5,1)

img = torch.zeros(IMG_SIZE)
img = img.type_as(leafs)
    
# isocenter as image origin
isocenter = 0.5 * torch.Tensor(IMG_SIZE)
isocenter = isocenter.type_as(leafs)
        
for leaf_index in range(leafs.shape[0]):
     leaf_pair = leafs[leaf_index, :]
     leaf_pair = torch.round(leaf_pair)
     x1 = isocenter[1] + leaf_pair[0] * IMG_RES[1]
     x2 = isocenter[1] + leaf_pair[1] * IMG_RES[1]
     
     x1 = x1.clamp(0, IMG_SIZE[1] - 1).int()
     x2 = x2.clamp(0, IMG_SIZE[1] - 1).int()
     y1 = leaf_index * IMG_RES[0]
     y2 = y1 + IMG_RES[0]
     img[y1:y2, x1:x2] = 1
     
plt.imshow(img)

The procedure dealing with this images is more complex to obtain a 3D volume - but differentiable because it just involves stacking up the images and rotate it, in the end I sum up all cubes and get an effective volume. Considering that I actually need this binary images in order to calculate these steps.
I do have the real aperture values, so I would do this for the real and the predicted apertures and take the L1/L2 loss of this 3D volume. I already did training on predicting the raw parameters which worked out well.
I’ve already had a look on methods proposed in other threads concerning my issue like grid sampling or intersection over union as you’ve suggested. However, I do not think this can be applied in my case since the actual image is only an intermediate step. There might be no real workaround which would preserve the postprocessing of these images.
Best regards,
Marco