I am using torch with some semantic segmentation algorithms to produce a binary mask of the segmented images. I would then like to crop the images based on that mask. To be clea
For anyone else running into this. I found good luck with converting the torch binary mask tensor into type Double
, and then simply multiplying it using torch's cmul
function against each of the RGB channels. Basically, because the binary mask has a 1
in place of a segmented pixel, then the value will just remain. Whereas if it is outside the segmentation it has a 0
which when multiplied across the channels produces black. Saransh's answer is also good, and works well for open cv.