How to turn all parts of a binary image outside of an ellipse to zero.

1 回表示 (過去 30 日間)
Hardit Singh
Hardit Singh 2019 年 12 月 23 日
編集済み: Matt J 2019 年 12 月 23 日
I have the centeroid, major axis length, minor axis length, and orientation of an ellipse and I want to make everything outside of the ellipse on a binary image 0/black. How would I approach this?

回答 (1 件)

Matt J
Matt J 2019 年 12 月 23 日
編集済み: Matt J 2019 年 12 月 23 日
Express the elliptical region in equality form
(x-c).'*Q*(x-c)<=1
where c is the centroid, Q is the 2x2 matrix,
Q=R.'*diag(1./[a,b]).^2*R;
and R is a 2x2 rotation matrix.
Then test all pixels to see which satisfy the inequality. This can be vectorized as follows,
[x,y]=ndgrid((1:Nx)-cx,(1:Ny)-cy);
delta=[x(:),y(:)].';
mask= all( sum( (Q*delta).*delta )<=1 );
mask=reshape(mask, Nx,Ny);

製品


リリース

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by