Faster execution of poly2mask
4 views (last 30 days)
Show older comments
Hello everyone, I was wondering if anyone would know how to get this done differently than I do.
I have this image and defined the polygon by its vertices (shown in red), what I want is to be able to extract the value of the color from them by putting it in a vector like the one I show in the figure
When I implemented it I had used poly2mask but in the real case (the one I show here is a small example, my image is 8000X8000 pixels and the number of clipping rectangles is over 400, so poly2mask is very slow and I was looking for something faster.
Thank you very much.
2 Comments
Answers (1)
Image Analyst
on 14 Jun 2020
Try this:
m = randi(255, 11, 9) % Set up sample data.
% Define region
row1 = 1;
row2 = 4;
column1 = 7;
column2 = 8;
% Extract sub-image.
subImage = m(row1 : row2, column1 : column2);
% Reshape into row vector.
vec = reshape(subImage, 1, [])
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!