private BinaryMask GetInterpolatedMask(double z) { if (sliceDictionary.ContainsKey(z)) { return(sliceDictionary[z].BinaryMask); } RegionOfInterestSlice slice1 = GetClosestSlicePrevious(z); RegionOfInterestSlice slice2 = GetClosestSliceNext(z); double z1 = slice1?.ZCoord ?? 0, z2 = slice2?.ZCoord ?? 0; BinaryMask mask1 = slice1?.BinaryMask; BinaryMask mask2 = slice2?.BinaryMask; if (mask1 == null) { mask1 = new BinaryMask(XRange, YRange); z1 = slice2 != null ? slice2.ZCoord - 2 : z - 2; } if (mask2 == null) { mask2 = new BinaryMask(XRange, YRange); z2 = slice2 != null ? slice2.ZCoord + 2 : z + 2; } double frac = (z - z1) / (z2 - z1); BinaryMask interped = mask1.InterpolateWith(mask2, frac); return(interped); }
public void ComputeBinaryMask() { if (Polygons.Count > 1) { } for (int i = 0; i < Polygons.Count; i++) { BinaryMask.AddPolygon(Polygons[i]); } }
/// <summary> /// Finds whether a point is inside the ROI, by interpolating between ROI slices /// Only use this if you are checking a SINGLE point, otheriwse use ContainsXYCoordsInterpolated /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="z"></param> /// <returns></returns> public bool ContainsPointInterpolated(double x, double y, double z) { if (!ZRange.Contains(z)) { return(false); } BinaryMask mask = GetInterpolatedMask(z); return(mask.ContainsPoint(x, y)); }
/// <summary> /// Bulk processes whether an array of x and y coords are inside the roi, with interpolation /// </summary> /// <param name="xy">Vertices accessed by (row,col) </param> /// <param name="z"></param> /// <returns></returns> public bool[,] ContainsXYCoordsInterpolated(double[, ][] xy, double z) { BinaryMask mask = GetInterpolatedMask(z); int cols = xy.GetLength(1); int rows = xy.GetLength(0); bool[,] pointsInside = new bool[rows, cols]; for (int col = 0; col < cols; col++) { for (int row = 0; row < rows; row++) { pointsInside[row, col] = mask.ContainsPoint(xy[row, col][0], xy[row, col][1]); } } return(pointsInside); }
/// <summary> /// Interpolates between two binary masks. /// See Schenk et. al Efficient Semiautomatic Segmentation of 3D objects in Medical Images /// Note this DOES NOT CURRENTLY WORK. Needs tweaking /// </summary> /// <param name="mask2"></param> /// <param name="frac">0 is all this mask, 1 is all mask 2</param> /// <returns></returns> public BinaryMask InterpolateWith(BinaryMask mask2, double frac) { BinaryMask newMask = new BinaryMask(XRange, YRange); float[] m1distance = BinaryMath.DistanceTransform(InsideBinaryData); float[] m2distance = BinaryMath.DistanceTransform(mask2.InsideBinaryData); newMask.InsideBinaryData = new bool[InsideBinaryData.Length]; for (int i = 0; i < m1distance.Length; i++) { var dist = m1distance[i] * (1 - frac) + m2distance[i] * (frac); if (dist <= 0) { newMask.InsideBinaryData[i] = true; } } return(newMask); }
public bool ContainsPoint(double x, double y) { return(BinaryMask.ContainsPoint(x, y)); }
public RegionOfInterestSlice() { Polygons = new List <PlanarPolygon>(); BinaryMask = new BinaryMask(); }