Matlab & Simulink Coder: Using a polygon shaped ROI to mask an input image

4 Ansichten (letzte 30 Tage)
Lars
Lars am 27 Mär. 2020
Bearbeitet: Lars am 3 Apr. 2020
Hi Everyone,
I am trying to use Simulink to take a greyscale image and mask a region of interest (polygonal). My goal is to use these values as input for for my control system. The code should be exported with Simulink Coder to a RT system afterwards.
My first idea was to use the Computer Vision Toolbox but I can't come up with an appropriate function here. My second try was to use a MATLAB function and use poly2mask() to extract the region of interest, but it's obviously not supported for Code Generation.
Any ideas how I could approach my problem next?
Thanks,
Lars

Antworten (1)

Lars
Lars am 3 Apr. 2020
Bearbeitet: Lars am 3 Apr. 2020
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?

Kategorien

Mehr zu Deployment, Integration, and Supported Hardware finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by