Faster execution of poly2mask

4 visualizaciones (últimos 30 días)
Alejandro Fernández
Alejandro Fernández el 2 de Jun. de 2020
Editada: darova el 15 de Jun. de 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 comentarios
darova
darova el 14 de Jun. de 2020
Editada: darova el 15 de Jun. de 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 el 14 de Jun. de 2020
darova - please fix. You know I1(x1:x2,y1:x2); is not correct.

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
Image Analyst el 14 de Jun. de 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 comentario
Alejandro Fernández
Alejandro Fernández el 15 de Jun. de 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?

Iniciar sesión para comentar.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by