In the meantime I came up with the following code
function extractedTemps = extractPolygon(tempImage, vertices) %#codegen
% Inputs: Image & vertices(x, y)
% Get image size
[iY, iX] = size(tempImage);
% Coordinates to all pixel
[x, y] = meshgrid(1:iX, 1:iY);
% Check if in polygon
[in] = inpolygon(x,y, vertices(1,:), vertices(2,:));
% Extract Temperatures
coder.varsize('extractedTemps',[21504 1]);
extractedTemps = tempImage(sub2ind(size(tempImage),y(in), x(in)));
Unfortunately diagnostics still gives me the follow error:
Saturate on overflow detected. In MATLAB Function 'ExtractPolygon': function extractedTemps = extractPolygon(tempImage, vertices) %#codegen
Any idea whats happening here?