Skip to content

Instantly share code, notes, and snippets.

"""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
@mauigna06
mauigna06 / testExampleOfRotation.py
Last active September 9, 2022 02:45
Allow to define rotations with sliders
# 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
@mauigna06
mauigna06 / transformModel.py
Last active February 15, 2022 09:23
This scripts allows 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.
# 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
@mauigna06
mauigna06 / SVDFrameOfModel.py
Created November 5, 2021 19:56
Create a frame for the model in the principal components directions, set up a plane with interaction handles to move it.
# 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:
@mauigna06
mauigna06 / SVDRegistrationWithScaling
Created October 30, 2021 12:42
Register two similar bones that has diffences in position, orientation and size (scaling)
import numpy as np
#SVD Registration
boneModel0 = getNode('bone0')
boneModel1 = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLModelNode',"bone1")
boneModel1.CreateDefaultDisplayNodes()
boneModel1.CopyContent(boneModel0)
boneModel1DisplayNode = boneModel1.GetDisplayNode()
@mauigna06
mauigna06 / copyPasteOnSlicer.py
Created October 29, 2021 20:42
This an example of registration by SVD decomposition of the data. Useful to register very similar bones
#Posted example
import numpy as np
#SVD Registration
boneModel0 = getNode('deformedBone')
boneModel1 = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLModelNode',"fibulaMoved")
boneModel1.CreateDefaultDisplayNodes()
boneModel1.CopyContent(boneModel0)