The correct approach is to convert matlab's built-in class object, imref2d, to struct types as output, e.g. these write a conversion function:
function outputStruct = helperToStructOutput(output)%#codegen
% input argument `output` is imref2d object.
outputStruct.ImageSize = output.ImageSize;
outputStruct.XWorldLimits = output.XWorldLimits;
outputStruct.YWorldLimits = output.YWorldLimits;
end