How to cover an irregular closed area with square pixels

2 ビュー (過去 30 日間)
Maura E. Monville
Maura E. Monville 2019 年 6 月 4 日
コメント済み: Maura E. Monville 2019 年 6 月 5 日
I have a set of closed curves described by the (x,y) coordinates of the approximating polygon.
My task is to cover the area enclosed by each curve with square pixel whose side is input.
No piece of the area must be left uncovered. That implies the squares covering the curve rim will lie partially inside and partially outside the curve.
In the following I describe what I have done.
  1. Generate a square grid of points inside or on the edge of the curve
  2. Generate new points lying outside the closed curve by subtracting the pixel side in the x or in the y direction
  3. Use Matlab function "rectangle" to build the square pixel.
  4. Eventually I will store to a file the coordinates of each pixel in the form X_min X_max Y_min Y_max
My problem is that some points, generated outside the closed curve, give rise to pixels that are completely outside the closed area. They do not intersect it.
I am attaching my script "Pixelize_Collimator_Aperture.m", my function "CollimatorGrid.m", and a zipped file containing the pictures of the resulting pixelized closed areas
I am pretty sure there are smarter ways to address this task. I would appreciate any suggestion and/or comment.
Thank you in advance.
Maura E.

回答 (1 件)

KSSV
KSSV 2019 年 6 月 4 日
Check the code:
R = 1. ;
C = [0. 0.] ;
th = linspace(0,2*pi) ;
xc = C(1)+R*cos(th) ;
yc = C(1)+R*sin(th) ;
% Make grid
m = 50 ; n = 50 ;
xi = linspace(min(xc),max(xc),m) ;
yi = linspace(min(yc),max(yc),n) ;
[X,Y] = meshgrid(xi,yi) ;
idx = inpolygon(X(:),Y(:),xc,yc) ;
X(~idx) = NaN ;
Y(~idx) = NaN ;
figure
hold on
plot(xc,yc,'b')
plot(X,Y,'r')
plot(X',Y','r')
  3 件のコメント
KSSV
KSSV 2019 年 6 月 4 日
That also can be taken care. You can use fill or patch eh.
Maura E. Monville
Maura E. Monville 2019 年 6 月 5 日
The reason why I am covering the closed areas with square pixels is because these areas are the axial sections of custom made collimators used for proton therapy of eye tumors.
The custom made colimator has to be added as a component of the synchrotron Monte Carlo model implemented with Fluka (non my choice).
Unluckily, Fluka cannot import CAD files which most modern Monte Carlo packages can.
Fluka approximates the custom made collimator reading a text file that contains the coordinates of the pixel in the form (Xmin Xmax Ymin Ymax). Then Fluka adds the same depth coordinate for each pixel, therefore transforming pixels into voxels.
Pixels must be square for Fluka to read them in.
The size of the square pixels does not need to be the same all over the closed area.
Actually, it would be desirable to make the pixels across the rim of the area smaller than the pixels completely contained inside the area.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeBounding Regions についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by