Skip to content
Snippets Groups Projects
Skeleton 3D.ipynb 7.45 KiB
Newer Older
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 232,
   "metadata": {},
   "outputs": [],
   "source": [
    "using MAT\n",
    "using Images\n",
    "using LinearAlgebra\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Skeleton3D (generic function with 1 method)"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "include(\"./julia/Skeleton3D.jl\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 267,
   "metadata": {},
   "outputs": [],
   "source": [
    "vars = matread(\"./julia/testvol.mat\");\n",
    "skel=vars[\"testvol\"]\n",
    "skel=padarray(skel,Pad(1, 1,1));\n",
    "width = size(skel,1);\n",
    "height = size(skel,2);\n",
    "depth = size(skel,3);\n",
    "\n",
    "skel=Int8.(reshape(skel[:],width,height,depth));\n",
    "\n",
    "# if (nargin==2)\n",
    "#     spare=padarray(spare,Pad(1, 1,1));\n",
    "# end\n",
    "\n",
    "\n",
    "# fill lookup table\n",
    "eulerLUT = FillEulerLUT();\n",
    "\n",
    "unchangedBorders = 0;"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 269,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3523-element Array{Int64,1}:\n",
       "   9430\n",
       "   9431\n",
       "   9432\n",
       "   9433\n",
       "   9434\n",
       "   9435\n",
       "   9436\n",
       "   9497\n",
       "   9632\n",
       "  10042\n",
       "  10085\n",
       "  10086\n",
       "  10087\n",
       "      ⋮\n",
       " 119864\n",
       " 119913\n",
       " 119914\n",
       " 119990\n",
       " 119991\n",
       " 119996\n",
       " 120055\n",
       " 120056\n",
       " 120057\n",
       " 120060\n",
       " 120061\n",
       " 120063"
      ]
     },
     "execution_count": 269,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "currentBorder=1\n",
    "# while (unchangedBorders < 6 )  # loop until no change for all six border types\n",
    "#     unchangedBorders = 0;\n",
    "#     for currentBorder=1:6 # loop over all 6 directions\n",
    "        cands=fill(false,width,height,depth); ##ok<LOGL>\n",
    "#         cands=false(width,height,depth, \"like\", skel);\n",
    "        if currentBorder==4\n",
    "            x=2:size(skel,1); # identify border voxels as candidates\n",
    "            cands[x,:,:]=((skel[x,:,:] - skel[x.-1,:,:]) .!= 0);\n",
    "        elseif currentBorder==3\n",
    "            x=1:size(skel,1)-1;\n",
    "            cands[x,:,:]=((skel[x,:,:] - skel[x.+1,:,:]) .!= 0);\n",
    "        elseif currentBorder==1\n",
    "            y=2:size(skel,2);\n",
    "            cands[:,y,:]=((skel[:,y,:] - skel[:,y.-1,:]) .!= 0);\n",
    "        elseif currentBorder==2\n",
    "            y=1:(size(skel,2)-1);\n",
    "            cands[:,y,:]=((skel[:,y,:] - skel[:,y.+1,:]) .!= 0);\n",
    "        elseif currentBorder==6\n",
    "            z=2:size(skel,3);\n",
    "            cands[:,:,z]=((skel[:,:,z] - skel[:,:,z.-1]) .!= 0);\n",
    "        elseif currentBorder==5\n",
    "            z=1:size(skel,3)-1;\n",
    "            cands[:,:,z]=((skel[:,:,z] - skel[:,:,z.+1]) .!= 0);\n",
    "        end\n",
    "\n",
    "        cands[:]=cands[:] .==1 .& skel[:] .==1\n",
    "        cands1=cands[:] .==1 .& skel[:] .==1\n",
    "\n",
    "        noChange = true;\n",
    "        if sum(cands1)>0\n",
    "                cands = findall(n -> n != 0, cands)\n",
    "                x=map(x->x[1],cands)\n",
    "                y=map(x->x[2],cands)\n",
    "                z=map(x->x[3],cands)\n",
    "    \n",
    "                cands = findall(n -> n != 0, cands1)\n",
    "        end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 272,
   "metadata": {},
   "outputs": [
    {
     "ename": "LoadError",
     "evalue": "UndefVarError: ind2sub not defined",
     "output_type": "error",
     "traceback": [
      "UndefVarError: ind2sub not defined",
      "",
      "Stacktrace:",
      " [1] pk_get_nh(::Array{Int8,3}, ::Array{Int64,1}) at C:\\Users\\amira\\Dropbox (MIT)\\CBA\\MetaVoxels\\metavoxels-code\\voxel_designer\\julia\\Skeleton3D.jl:715",
      " [2] top-level scope at In[272]:1",
      " [3] include_string(::Function, ::Module, ::String, ::String) at .\\loading.jl:1091",
      " [4] execute_code(::String, ::String) at C:\\Users\\amira\\.julia\\packages\\IJulia\\rWZ9e\\src\\execute_request.jl:27",
      " [5] execute_request(::ZMQ.Socket, ::IJulia.Msg) at C:\\Users\\amira\\.julia\\packages\\IJulia\\rWZ9e\\src\\execute_request.jl:86",
      " [6] #invokelatest#1 at .\\essentials.jl:710 [inlined]",
      " [7] invokelatest at .\\essentials.jl:709 [inlined]",
      " [8] eventloop(::ZMQ.Socket) at C:\\Users\\amira\\.julia\\packages\\IJulia\\rWZ9e\\src\\eventloop.jl:8",
      " [9] (::IJulia.var\"#15#18\")() at .\\task.jl:356"
     ]
    }
   ],
   "source": [
    "nhood = pk_get_nh(skel,cands);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 249,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3523-element Array{Int64,1}:\n",
       "   9430\n",
       "   9431\n",
       "   9432\n",
       "   9433\n",
       "   9434\n",
       "   9435\n",
       "   9436\n",
       "   9497\n",
       "   9632\n",
       "  10042\n",
       "  10085\n",
       "  10086\n",
       "  10087\n",
       "      ⋮\n",
       " 119864\n",
       " 119913\n",
       " 119914\n",
       " 119990\n",
       " 119991\n",
       " 119996\n",
       " 120055\n",
       " 120056\n",
       " 120057\n",
       " 120060\n",
       " 120061\n",
       " 120063"
      ]
     },
     "execution_count": 249,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x,y,z=Base._sub2ind((width,height,depth),cands)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 250,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9430"
      ]
     },
     "execution_count": 250,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 251,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9431"
      ]
     },
     "execution_count": 251,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 252,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9432"
      ]
     },
     "execution_count": 252,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "z"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 253,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(3523,)"
      ]
     },
     "execution_count": 253,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "size(Base._sub2ind((width,height,depth),cands))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Julia 1.5.2",
   "language": "julia",
   "name": "julia-1.5"
  },
  "language_info": {
   "file_extension": ".jl",
   "mimetype": "application/julia",
   "name": "julia",
   "version": "1.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}