Exemplo n.º 1
0
    def _generate_image_gradients(self):
        """
        Provides GVF gradients in the x, y, and z directions
        """

        # Maybe should give access to parameters
        v = GVF3D(self.image_sequence.gradient().array, self.GVF_mu,
                  self.GVF_iter, self.GVF_verbose)
        self.image_gradients = [
            ImageSequence(array=direction) for direction in v
        ]
Exemplo n.º 2
0
    def _generate_image_gradients(self):
        """
        Generate image gradients
        """
        #self.image_gradients = self._image_sequence.gradient()
        out = GVF3D(self.image_sequence.array,
                    self.GVF_mu,
                    self.GVF_iter,
                    verbose=self.verbose)

        gradient = ImageSequence(array=-np.linalg.norm(out, axis=0))
        self.image_gradients = gradient
                                 k=k,
                                 per=1)

    t, c, k = tck
    c = np.array(c).T

    if return_spline:
        spline = interpolate.BSpline(t, c, k, extrapolate='periodic')
        return spline
    else:
        return t, c, k


# %%
file = 'testfiles/aortic_cross_section.gif'
imseq = ImageSequence(file)

img = np.array(imseq.return_image(0))
img = rgb2gray(img)

# %% Parameters
maxiter = 40
num_ctrlpts = 20  # for easy comparison, we convert trad to bspline

# Something to have the same basis
s = np.linspace(0, 2 * np.pi, 200)
r = 50 + 20 * np.sin(s)
c = 50 + 20 * np.cos(s)
init = np.array([r, c]).T

# %% Traditional
Author: Christophe Foyer

Description:
    This is an example script demonstrating 3D optimization of pre-optimized
    BSpline Surfaces using a hybrid 2D to 3D solver on an artificial dataset.
"""

# %% Imports
import numpy as np
from nurbs_active_contour.utils.image import ImageSequence
from nurbs_active_contour.optimize.hybrid_dimension_snakes import HybridSnakes
from nurbs_active_contour.optimize.solver3d import Solver3D

# Import the data
file = "testfiles/spline_tube_dataset_noisy.gif"
imseq = ImageSequence(file)
imseq.change_resolution((200, 200, 200))

# Set input spline geometry
y = [30, 50, 60, 90]
x = [30, 60, 50, 40]
z = [0, 30, 80, 40]
array = np.stack([x, y, z]) * 2

# %% Hybrid Snake
# Options
kwargs = {
    'plane_extent': (100, 100),
    'plane_shape': (100, 100),
    'n': 10,
    'init_spline_size': 10
Exemplo n.º 5
0
    [m,n] = A.shape;
    yi = np.arange(0, m-1);
    xi = np.arange(0, n-1);
    B = A[np.ix_(yi,xi)];
    
    return B


# %%
if __name__ == "__main__":
    from nurbs_active_contour.utils.image import ImageSequence
    file = "../../../examples/testfiles/aortic_cross_section.gif"
    # file = "../../../examples/testfiles/MRI_SUB1_subset/SUB1_subset/"
    # file = "../../examples/testfiles/CARDIAC_CT_ANGIO_(_Retro)_11/"
    imseq = ImageSequence(file)
    imseq.change_resolution((100, 100, -1))
    # imseq = imseq.gradient()
    
    img = np.array(imseq.return_image(1))
    
    # shape = img.shape
    
    # imgpad = np.zeros((np.array(img.shape)+3))
    # imgpad[:shape[0], :shape[1]] = img
    # img = imgpad
    
    from skimage.filters import gaussian
    img = gaussian(img, 1)
    
    out = np.array(GVF(img, 0.001, 1000, pad_image=10))
from nurbs_active_contour.utils.utilities import generate_knots
from nurbs_active_contour.optimize.solver2d import Solver2D
from nurbs_active_contour.utils.image import ImageSequence

from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
from matplotlib.colors import Colormap as cm
from matplotlib import cm as cm2

import pyvista as pv

# %% Solve a 2D problem

# Import an image
file = "../examples/testfiles/aortic_cross_section.gif"
image = np.array(ImageSequence(file).return_image(1))

# Create a B-Spline curve instance
curve = ClosedRationalQuadraticCurve()

# Add some control points
points = (np.array([[0, 0], [0, 0.5],
                    [0, 1], [0.5, 1],
                    [1, 1], [1, 0.5],
                    [1, 0], [0.5, 0]]) * 0.5 + 0.25) \
    * (np.sqrt(image.size) - np.array([1, 1]))

curve.ctrlpts = points

# Auto-generate knot vector
curve.knotvector = generate_knots(curve)
Exemplo n.º 7
0
"""
Author: Christophe Foyer

Description:
    This is an example for 3D gradient vector flow.
"""

# %% Imports
from nurbs_active_contour.utils.GVF import GVF3D
from nurbs_active_contour.utils.image import ImageSequence
import pyvista as pv
import numpy as np

file = "./testfiles/aortic_cross_section.gif"
imseq = ImageSequence(file)
imseq = imseq.gradient()
imseq.change_resolution((100, 100, 100))

[u, v, w] = GVF3D(imseq.array, 0.02, 1000, verbose=True)

# %% Plot vectors
grid = pv.UniformGrid()
grid.dimensions = imseq.array.shape
grid.point_arrays["values"] = imseq.array.flatten(order="F")
grid['vectors'] = np.stack([u, v, w]).reshape(3, -1).T

arrows = grid.glyph(
    orient='vectors',
    scale=True,
    factor=1E-1,
)