View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Blended 3D poly2mask

5.0 | 1 rating Rate this file 15 Downloads (last 30 days) File Size: 2.63 KB File ID: #37863 Version: 1.3
image thumbnail

Blended 3D poly2mask


Sven (view profile)


21 Aug 2012 (Updated )

Creates a 3D mask "lofted" or "tweened" (blended smoothly) from a set of planar polygons.

| Watch this File

File Information

If you have two polygons and want two masks, you can just call poly2mask separately on each polygon. Now imagine these two 2D polygons are hovering at Z=1 and Z=10, and you want to make a mask *volume* along the slices Z=1:10. For that, you want blendedPolyMask.

 BLENDEDPOLYMASK Creates a 3D mask "lofted" from a set of polygons
  BW = BLENDEDPOLYMASK(C,X,Y,Z) returns a logical volume of size equal to
  [length(Y) length(X) length(Z)]. C is a cell array of N-by-3 XYZ
  coordinates specifying individual (planar) XY polygons. The first
  Z-coordinate of each polygon in C specifies its planar location. X, Y
  and Z are vectors specifying pixel locations in the 3D output volume.
  The output BW is a "loft" from one polygon to the next. Interpolation
  between polygons is done via the distance function of the masks at each
  neighbouring polygon. The IP toolbox BWDIST function is required.

    [circXY(:,1),circXY(:,2)] = pol2cart(linspace(0,2*pi,50)', 1);
    sqXY = [-1 -1;1 -1;1 1;-1 1; -1 -1];
    C = {[sqXY*5 ones(5,1)] % Start with a small square
        [circXY*40 ones(50,1)*30] % Blend to a large circle
        [sqXY*20 ones(5,1)*65] % Blend to a large square
        [circXY*10 ones(50,1)*99]}; % Blend to a small circle
    X = linspace(-40, 40, 200);
    Y = linspace(-40, 40, 200);
    Z = linspace(0, 100, 400);
    BW = blendedPolymask(C,X,Y,Z);
    figure, patch(isosurface(X,Y,Z,BW,0.5),'FaceColor','g','EdgeColor','none','FaceAlpha',0.5)
    view(3), camlight, hold on, axis image

Required Products Image Processing Toolbox
MATLAB release MATLAB 7.14 (R2012a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (1)
27 Feb 2014 tong luo

GREAT ! as interp3 can not interpolate bianry value with such as geometrical position transition.

23 Aug 2012 1.1

Some typos in the help file have been cleared up to reflect the true input order of arguments.

06 Nov 2012 1.2

Minor bug fixed whereby query levels outside the range of curves would incorrectly return the first curve mask

12 Feb 2013 1.3

Fixed bug where any curveZlocations exactly hitting a usedBWmask used an inappopriate mask

Contact us