def execute(self, slot, subindex, roi, result):
        # Remove i,j slices from roi, append channel slice to roi.
        input_roi = ( tuple(roi.start[:-2]) + (0,),
                      tuple(roi.stop[:-2]) + (1,) )

        enlarged_roi, result_roi = self._enlarge_roi_for_halo(*input_roi)
        
        # Request input
        input_data = self.Input(*enlarged_roi).wait()
        
        # Drop singleton channel axis
        input_data = input_data[...,0]
        
        # We need a uint8 array, in C-order.
        input_data = input_data.astype( numpy.uint8, order='C', copy=False )

        # Compute. (Note that we drop the 
        eigenvectors = computeEigenVectorsOfHessianImage(input_data, 
                                                         zAnisotropyFactor=self.z_anisotropy_factor, 
                                                         sigma=self.Sigma.value)
        
        # sanity checks...
        assert (eigenvectors.shape[:-2] == (numpy.array(enlarged_roi[1]) - enlarged_roi[0])[:-1]).all(), \
            "eigenvector image has unexpected shape: {}".format( eigenvectors.shape )
        assert eigenvectors.shape[-2:] == (3,3)

        # Copy to output.
        
        result[:] = eigenvectors[roiToSlice(*result_roi)][..., slice(roi.start[-1], roi.stop[-1])]
    def execute(self, slot, subindex, roi, result):
        # Remove i,j slices from roi, append channel slice to roi.
        input_roi = ( tuple(roi.start[:-2]) + (0,),
                      tuple(roi.stop[:-2]) + (1,) )

        enlarged_roi, result_roi = self._enlarge_roi_for_halo(*input_roi)
        
        # Request input
        input_data = self.Input(*enlarged_roi).wait()
        
        # Drop singleton channel axis
        input_data = input_data[...,0]
        
        # We need a uint8 array, in C-order.
        input_data = input_data.astype( numpy.uint8, order='C', copy=False )

        # Compute. (Note that we drop the 
        eigenvectors = computeEigenVectorsOfHessianImage(input_data, 
                                                         zAnisotropyFactor=self.z_anisotropy_factor, 
                                                         sigma=self.Sigma.value)
        
        # sanity checks...
        assert (eigenvectors.shape[:-2] == (numpy.array(enlarged_roi[1]) - enlarged_roi[0])[:-1]).all(), \
            "eigenvector image has unexpected shape: {}".format( eigenvectors.shape )
        assert eigenvectors.shape[-2:] == (3,3)

        # Copy to output.
        
        result[:] = eigenvectors[roiToSlice(*result_roi)][..., slice(roi.start[-1], roi.stop[-1])]
Пример #3
0
imgFloat = np.float32(img)
iiImage = computeIntegralImage( imgFloat )

# again, this is stupid, just presume the second channel is a different feature
channel1 = iiImage
channel2 = iiImage
channels3 = channels2 = channels1 = [channel1,channel2]

# anisotropy factor is the ratio between z voxel size and x/y voxel size.
# if Isotropic -> 1.0
zAnisotropyFactor = 1.0;

# this is typically a good value, but it depends on the voxel size of the data
hessianSigma = 3.5

eigV1 = computeEigenVectorsOfHessianImage( img1, zAnisotropyFactor, hessianSigma )
eigV2 = computeEigenVectorsOfHessianImage( img2, zAnisotropyFactor, hessianSigma )
eigV3 = computeEigenVectorsOfHessianImage( img3, zAnisotropyFactor, hessianSigma )

# Train: note that we pass a list of stacks
model.trainWithChannels( [img1,img2,img3], [eigV1, eigV2, eigV3], [gt1,gt2,gt3], [channels1,channels2,channels3], 
                         zAnisotropyFactor, numStumps=100, gtNegativeLabel=1, gtPositiveLabel=2, debugOutput=True)

pred = model.predictWithChannels( img, eigV1, channels1, zAnisotropyFactor, useEarlyStopping=True)

roi = ROICoordinates()
roi.x2 = img.shape[2] - 1
roi.y2 = img.shape[1] - 1
roi.z1 = roi.z2 = img.shape[0] / 2

predSingleSlice = model.predictWithChannels( img, eigV1, channels1, zAnisotropyFactor, useEarlyStopping=True, subROI=roi)
from iiboost import  computeEigenVectorsOfHessianImage
from sklearn.externals import joblib    # to load data

import numpy as np

# to show something
import matplotlib.pyplot as plt

# load data
from os.path import split, join
data_dir = join(split(__file__)[0], '../../testData')
gt = joblib.load(data_dir + "/gt.jlb")
img = joblib.load(data_dir + "/img.jlb")

# compute eigen vector image
eigenvectors = computeEigenVectorsOfHessianImage(gt, zAnisotropyFactor=1.0, sigma=1.0)