Faster execution of poly2mask

조회 수: 5 (최근 30일)
Alejandro Fernández
Alejandro Fernández 2020년 6월 2일
편집: darova 2020년 6월 15일
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
darova
darova 2020년 6월 14일
편집: darova 2020년 6월 15일
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 2020년 6월 14일
darova - please fix. You know I1(x1:x2,y1:x2); is not correct.

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2020년 6월 14일
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
Alejandro Fernández
Alejandro Fernández 2020년 6월 15일
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?

댓글을 달려면 로그인하십시오.

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by