Extracting non square/rectangular patch

is there a way to extract non square/rectangular patch, like, extract a + or a circle, from an image, is there any research going on in this direction?
what would the shape of such a tensor be?

Typically, one uses masks. Either directly or to index with a boolean mask, which gives you an arbitray selection of pixels in a flattened tensor, e.g. for a circle, you can use

mask = (torch.linspace(-1, 1)[None]**2+torch.linspace(-1, 1)[:, None]**2)<0.5**2

Best regards

Thomas

hello, thanks for your reply, the technique you describe do appear to work if my neural network already know the shape that it has to extract, but the problem be that it has no idea what shape it has to extract, it is only given an image, so information about what does a particular shape look like is not an input.

for example, if I see an image that I have never seen before, and I do not know what is that image about, still I am able to extract patches from it, of non square/rectangular shape.

currently the only way I know is to use unfold, that also, to extract square/rectangular patch, that also, I will have to manually input the shape of the patch that I want to extract.

Yeah, well. You can combine the masking with unfold to get a series of patches.
For “extracting the right thing if you don’t know what it is” (which is how the first paragraph sounds to me) you likely need someone more competent to answer.

Best regards

Thomas