This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Estimating 3d coordinates from an RGB image | |
Support for the "Estimating 3d coordinates from an RGB image" | |
blog post in d3rezz.github.io | |
""" | |
import cv2 | |
import numpy as np | |
import time | |
import matplotlib.pyplot as plt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# save in a len=3 buffer the last moved sliders | |
# generate transform for slider combination according to dictionary consulted by the buffer | |
# calculate transform in bufferOrder and set sliders | |
import math | |
import numpy as np | |
#source https://github.com/matthew-brett/transforms3d/blob/52321496a0d98f1f698fd3ed81f680d740202553/transforms3d/_gohlketransforms.py#L1680 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This scripts allows you to have a widget placed initially in the model centroid and the | |
# direction matching its principal components. Then two modes are possible "Transform mode" | |
# and "Local mode" by pressing g key and h key correspondingly. | |
# You can change the center of rotation by going to Local mode, moving the widget and then | |
# returning to Transform mode. This feature that let's move the plane indenpendently of the | |
# model on Local mode and then lets you transform it in Transform mode is what makes this | |
# feature useful for manual registration. | |
# Code Starts here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create a frame for the model in the principal components directions, | |
# set up a plane with interaction handles to move it. | |
import numpy as np | |
#Change this number for more accuracy (more points, take more time to compute) | |
numberOfSampledPointsOfModel = 2000 | |
model = getNode('mymodel') | |
if model.GetPolyData().GetNumberOfPoints() > numberOfSampledPointsOfModel: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
#SVD Registration | |
boneModel0 = getNode('bone0') | |
boneModel1 = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLModelNode',"bone1") | |
boneModel1.CreateDefaultDisplayNodes() | |
boneModel1.CopyContent(boneModel0) | |
boneModel1DisplayNode = boneModel1.GetDisplayNode() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Posted example | |
import numpy as np | |
#SVD Registration | |
boneModel0 = getNode('deformedBone') | |
boneModel1 = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLModelNode',"fibulaMoved") | |
boneModel1.CreateDefaultDisplayNodes() | |
boneModel1.CopyContent(boneModel0) |