Effacer les filtres
Effacer les filtres

Faster execution of poly2mask

1 vue (au cours des 30 derniers jours)
Alejandro Fernández
Alejandro Fernández le 2 Juin 2020
Modifié(e) : darova le 15 Juin 2020
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 commentaires
darova
darova le 14 Juin 2020
Modifié(e) : darova le 15 Juin 2020
Since you know the coordinates why don't just cut that region?
reg1 = I1(x1:x2,y1:y2);
EDITED: edited the code
Image Analyst
Image Analyst le 14 Juin 2020
darova - please fix. You know I1(x1:x2,y1:x2); is not correct.

Connectez-vous pour commenter.

Réponses (1)

Image Analyst
Image Analyst le 14 Juin 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, [])
  1 commentaire
Alejandro Fernández
Alejandro Fernández le 15 Juin 2020
Ok thank you so much, just one more question, If the rectangle shown in red in the image was rotated a certain angle, the poly2mask function would become essential or you can also modify the code you just passed me?

Connectez-vous pour commenter.

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by