From f79b1e187041642d9e06ffbc12fa3a27b1412983 Mon Sep 17 00:00:00 2001 From: Eric Wait <eric@waitphoto.com> Date: Thu, 30 Mar 2017 16:26:18 -0400 Subject: [PATCH] Attempting to fix the hull vert offset when making polygons --- src/matlab/+D3d/+Polygon/Make.m | 34 ++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/matlab/+D3d/+Polygon/Make.m b/src/matlab/+D3d/+Polygon/Make.m index 31efcdf..0f8825d 100644 --- a/src/matlab/+D3d/+Polygon/Make.m +++ b/src/matlab/+D3d/+Polygon/Make.m @@ -25,31 +25,39 @@ if (~exist('quiet','var') || isempty(quiet)) quiet = false; end +reductions = [1,1,1]; + polygon = D3d.Polygon.MakeEmptyStruct(); % padd the subimage to get some room to blur PADDING = ceil(5*1./reductions); -maxExtent_rc = Utils.SwapXY_RC(max(pixelList_xy,[],1)) + PADDING; -indList = Utils.CoordToInd(maxExtent_rc,Utils.SwapXY_RC(pixelList_xy)); -[im,startCoords_rcz] = ImUtils.ROI.MakeSubImBW(maxExtent_rc,indList,PADDING); -startCoords_xy = Utils.SwapXY_RC(startCoords_rcz); +startCoords_rcz = Utils.SwapXY_RC(min(pixelList_xy,[],1)); +endCoords_rcz = Utils.SwapXY_RC(max(pixelList_xy,[],1)); + +startPadded = startCoords_rcz-PADDING; +endPadded = endCoords_rcz+PADDING; + +roiIm = false(endPadded-startPadded+1); + +paddedPixelList_rcz = Utils.SwapXY_RC(pixelList_xy)-startPadded+1; +indList = Utils.CoordToInd(size(roiIm),paddedPixelList_rcz); +roiIm(indList) = true; cc.Connectivity = 26; -cc.ImageSize = size(im); +cc.ImageSize = size(roiIm); cc.NumObjects = 1; -cc.PixelIdxList = {find(im)}; +cc.PixelIdxList = {indList}; rp = regionprops(cc,'Centroid'); -imR = ImProc.Resize(im2uint8(im),reductions,[],'mean'); +imR = ImProc.Resize(im2uint8(roiIm),reductions,[],'mean'); -endCoords_rcz = startCoords_rcz + floor((maxExtent_rc - startCoords_rcz).*reductions)./reductions; -R = linspace(startCoords_rcz(1),endCoords_rcz(1),size(imR,1)); -C = linspace(startCoords_rcz(2),endCoords_rcz(2),size(imR,2)); -Z = linspace(startCoords_rcz(3),endCoords_rcz(3),size(imR,3)); +R = linspace(startPadded(1),endPadded(1),size(imR,1)); +C = linspace(startPadded(2),endPadded(2),size(imR,2)); +Z = linspace(startPadded(3),endPadded(3),size(imR,3)); [x,y,z] = meshgrid(C,R,Z); -[faces, v_xy] = isosurface(x,y,z,imR,160); +[faces, v_xy] = isosurface(x,y,z,imR,1); if (isempty(v_xy)) return @@ -58,7 +66,7 @@ end % center the vert in the middle of the voxel verts_xy = v_xy + 0.5; -com = rp.Centroid + startCoords_xy -1; +com = rp.Centroid + startPadded -1; if (any(faces(:)==0)) error('there is a zero index in the faces structure!'); -- GitLab