Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(registration): example (poc) #863

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 106 additions & 0 deletions packages/core/examples/registration/RegistrationConsole.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import * as hdf5 from 'jsfive';
import { getFormatedDateTime } from './utils';

class RegistrationConsole {
private _consoleRoot: HTMLElement;
private _logRoot: HTMLDivElement;

constructor(container) {
const { consoleRoot, logRoot } =
RegistrationConsole.createLogWindow(container);

this._consoleRoot = consoleRoot;
this._logRoot = logRoot;
}

private static createLogWindow(container) {
const statusFieldset = document.createElement('fieldset');
const statusFieldsetLegent = document.createElement('legend');
const logRoot = document.createElement('div');

Object.assign(statusFieldset.style, {
fontSize: '12px',
height: '200px',
overflow: 'scroll',
});

statusFieldsetLegent.innerText = 'Processing logs';
logRoot.style.fontFamily = 'monospace';

statusFieldset.appendChild(statusFieldsetLegent);
statusFieldset.appendChild(logRoot);
container.appendChild(statusFieldset);

return {
consoleRoot: statusFieldset,
logRoot,
};
}

public log(text, preFormated = false) {
const { _consoleRoot: consoleRoot, _logRoot: logRoot } = this;
const node = document.createElement(preFormated ? 'pre' : 'p');

node.innerHTML = `${getFormatedDateTime()} ${text}`;
node.style.margin = '0';
node.style.fontSize = '10px';
logRoot.appendChild(node);

// Scroll to the end
consoleRoot.scrollBy(0, consoleRoot.scrollHeight - consoleRoot.scrollTop);
}

public clear() {
const { _logRoot: logRoot } = this;
while (logRoot.hasChildNodes()) {
logRoot.removeChild(logRoot.firstChild);
}
}

/**
* Log all image information
*/
public logImageInfo(image) {
this.log(`image "${image.name}"`);
this.log(` origin: ${image.origin.join(', ')}`, true);
this.log(` spacing: ${image.spacing.join(', ')}`, true);
this.log(` direction: ${image.direction.join(', ')}`, true);
this.log(` size: ${image.size.join(', ')}`, true);
this.log(` imageType:`, true);
this.log(` dimension: ${image.imageType.dimension}`, true);
this.log(` components: ${image.imageType.components}`, true);
this.log(` componentType: ${image.imageType.componentType}`, true);
this.log(` pixelType: ${image.imageType.pixelType}`, true);
}

/**
* Log HDF5 transform and make it available for download
*/
public logTransform(transform) {
let buffer = transform.data.buffer;

// Convert SharedArrayBuffer into ArrayBuffer
if (buffer instanceof SharedArrayBuffer) {
buffer = new Uint8ClampedArray(buffer).slice().buffer;
}

const fileName = transform.path;
const hdfFile = new hdf5.File(buffer, transform.path);
const transformBlob = new Blob([buffer], { type: 'application/x-hdf5' });
const url = URL.createObjectURL(transformBlob);

this.log(
`Download <a href="${url}" download="${fileName}">${fileName}</a>`
);

console.log('Transform (HDF5):', hdfFile);
}

destroy() {
this._consoleRoot.remove();
this._consoleRoot = null;
this._logRoot = null;
}
}

export { RegistrationConsole as default, RegistrationConsole };
196 changes: 196 additions & 0 deletions packages/core/examples/registration/elastixParametersSettings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
const defaultNumberOfResolutions = 2;
const defaultFinalGridSpacing = 8;

const parametersSettings = {
NumberOfResolutions: {
inputType: 'number',
defaultValue: defaultNumberOfResolutions,
},
MaximumNumberOfIterations: {
inputType: 'number',
defaultValue: 256,
},
Registration: {
inputType: 'dropdown',
values: [
'MultiResolutionRegistration',
'MultiResolutionRegistrationWithFeatures',
'MultiMetricMultiResolutionRegistration',
],
},
Metric: {
inputType: 'dropdown',
values: [
'AdvancedKappaStatistic',
'AdvancedMattesMutualInformation',
'AdvancedMeanSquares',
'AdvancedNormalizedCorrelation',
'CorrespondingPointsEuclideanDistanceMetric',
'DisplacementMagnitudePenalty',
'DistancePreservingRigidityPenalty',
'GradientDifference',
'KNNGraphAlphaMutualInformation',
'MissingStructurePenalty',
'NormalizedGradientCorrelation',
'NormalizedMutualInformation',
'PCAMetric',
'PCAMetric2',
'PatternIntensity',
'PolydataDummyPenalty',
'StatisticalShapePenalty',
'SumOfPairwiseCorrelationCoefficientsMetric',
'SumSquaredTissueVolumeDifference',
'TransformBendingEnergyPenalty',
'TransformRigidityPenalty',
'VarianceOverLastDimensionMetric',
],
},
Interpolator: {
inputType: 'dropdown',
values: [
'BSplineInterpolator',
'BSplineInterpolatorFloat',
'LinearInterpolator',
'NearestNeighborInterpolator',
'RayCastInterpolator',
'ReducedDimensionBSplineInterpolator',
],
},
FixedImagePyramid: {
inputType: 'dropdown',
values: [
'FixedGenericImagePyramid',
'FixedRecursiveImagePyramid',
'FixedSmoothingImagePyramid',
'FixedShrinkingImagePyramid',
'OpenCLFixedGenericImagePyramid',
],
},
MovingImagePyramid: {
inputType: 'dropdown',
values: [
'MovingGenericImagePyramid',
'MovingRecursiveImagePyramid',
'MovingShrinkingImagePyramid',
'MovingSmoothingImagePyramid',
'OpenCLMovingGenericImagePyramid',
],
},
Optimizer: {
inputType: 'dropdown',
values: [
'AdaGrad',
'AdaptiveStochasticGradientDescent',
'AdaptiveStochasticLBFGS',
'AdaptiveStochasticVarianceReducedGradient',
'CMAEvolutionStrategy',
'ConjugateGradient',
'ConjugateGradientFRPR',
'FiniteDifferenceGradientDescent',
'FullSearch',
'Powell',
'PreconditionedGradientDescent',
'PreconditionedStochasticGradientDescent',
'QuasiNewtonLBFGS',
'RSGDEachParameterApart',
'RegularStepGradientDescent',
'Simplex',
'SimultaneousPerturbation',
'StandardGradientDescent',
],
},
Resampler: {
inputType: 'dropdown',
values: ['DefaultResampler', 'OpenCLResampler'],
},
ResampleInterpolator: {
inputType: 'dropdown',
values: [
'FinalBSplineInterpolator',
'FinalBSplineInterpolatorFloat',
'FinalLinearInterpolator',
'FinalNearestNeighborInterpolator',
'FinalReducedDimensionBSplineInterpolator',
'FinalRayCastInterpolator',
],
},
FinalBSplineInterpolationOrder: {
inputType: 'number',
},
ImageSampler: {
inputType: 'dropdown',
values: [
'Random',
'RandomCoordinate',
'Full',
'Grid',
'MultiInputRandomCoordinate',
'RandomSparseMask',
],
},
NumberOfSpatialSamples: {
inputType: 'number',
defaultValue: 2048,
},
CheckNumberOfSamples: {
inputType: 'dropdown',
values: ['true', 'false'],
defaultValue: 'true',
},
MaximumNumberOfSamplingAttempts: {
inputType: 'number',
defaultValue: 8,
},
NewSamplesEveryIteration: {
inputType: 'dropdown',
values: ['true', 'false'],
defaultValue: 'true',
},
NumberOfSamplesForExactGradient: {
inputType: 'number',
defaultValue: 4096,
},
DefaultPixelValue: {
inputType: 'number',
defaultValue: 0,
},
AutomaticParameterEstimation: {
inputType: 'dropdown',
values: ['true', 'false'],
defaultValue: 'true',
},
AutomaticScalesEstimation: {
inputType: 'dropdown',
values: ['true', 'false'],
defaultValue: 'true',
},
AutomaticTransformInitialization: {
inputType: 'dropdown',
values: ['true', 'false'],
defaultValue: 'true',
},
Metric0Weight: {
inputType: 'number',
defaultValue: '1.0',
step: 0.1,
},
Metric1Weight: {
inputType: 'number',
defaultValue: '1.0',
step: 0.1,
},
FinalGridSpacing: {
inputType: 'number',
defaultValue: defaultFinalGridSpacing,
},
// ResultImageFormat: {
// inputType: 'dropdown',
// values: ['mhd', 'nii', 'nrrd', 'vti'],
// },
};

export {
defaultNumberOfResolutions,
defaultFinalGridSpacing,
parametersSettings,
};
Loading