Skip to content

Commit

Permalink
added v1.2.2 files to git repo
Browse files Browse the repository at this point in the history
  • Loading branch information
jucestain committed Jun 16, 2017
1 parent 84b0599 commit d0705d7
Show file tree
Hide file tree
Showing 49 changed files with 23,496 additions and 0 deletions.
27 changes: 27 additions & 0 deletions license.txt
@@ -0,0 +1,27 @@
Copyright (c) 2017, Justin Blaber
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution
* Neither the name of the Georgia Institute of Technology nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
3,782 changes: 3,782 additions & 0 deletions ncorr.m

Large diffs are not rendered by default.

74 changes: 74 additions & 0 deletions ncorr_alg_addanalysis.m
@@ -0,0 +1,74 @@
function [plot_added,outstate] = ncorr_alg_addanalysis(plots_u,plots_v,rois,spacing,num_img,total_imgs)
% This function performs the adding of displacement fields. It will cycle
% through every point in the mask of the first ROI and attempt to propogate
% those points until the last displacement plot, so the added displacements
% will be WRT to the first plot's perspective.
%
% Inputs -----------------------------------------------------------------%
% plots_u - cell; u displacement plots
% plots_v - cell; v displacement plots
% rois - ncorr_class_roi; ROIs corresponding to the displacement plots.
% Note that rois will already be reduced by default.
% spacing - integer; spacing parameter
% num_img - integer; number of reference image being analyzed
% total_imgs - integer; total number of images being analyzed
%
% Outputs ----------------------------------------------------------------%
% plot_added - struct; contains
% struct('plot_u_added',{},'plot_v_added',{},'plot_validpoints',{})
% outstate - integer; returns either out.cancelled, out.failed, or
% out.success.

% Initialize outputs
outstate = out.cancelled;
plot_added = struct('plot_u_added',{},'plot_v_added',{},'plot_validpoints',{});

% Extrapolate displacement plots to improve interpolation near the
% boundary points.
% border_interp is the border added to the displacements when they are
% extrapolated.
border_interp = 20; % MUST BE GREATER THAN OR EQUAL TO 2
plots_u_interp = cell(0);
plots_v_interp = cell(0);
% Note that ncorr_alg_extrapdata will return a separate extrapolated
% array for each region within a ROI. This is done to prevent
% displacements from adjacent regions from influencing each other.
% Also note that the ordering returned forms a correspondence between
% the regions stored in rois.
for k = 0:length(plots_u)-1
plots_u_interp{k+1} = ncorr_alg_extrapdata(plots_u{k+1},rois(k+1).formatted(),int32(border_interp));
plots_v_interp{k+1} = ncorr_alg_extrapdata(plots_v{k+1},rois(k+1).formatted(),int32(border_interp));
end

% Convert displacement plots to B-spline coefficients; these are used
% for interpolation. Make sure to do this for each region.
for k = 0:length(plots_u_interp)-1
for l = 0:length(plots_u_interp{k+1})-1
plots_u_interp{k+1}{l+1} = ncorr_class_img.form_bcoef(plots_u_interp{k+1}{l+1});
plots_v_interp{k+1}{l+1} = ncorr_class_img.form_bcoef(plots_v_interp{k+1}{l+1});
end
end

% Format ROIs
rois_formatted = ncorr_class_roi.empty;
for k = 0:length(rois)-1
rois_formatted(k+1) = rois(k+1).formatted();
end

% Add plots to get the overall displacement field. ncorr_alg_adddisp
% returns either success or cancelled.
plot_added_prelim = struct('plot_u_added',{},'plot_v_added',{},'plot_validpoints',{});
[plot_added_prelim(1),outstate_add] = ncorr_alg_adddisp(plots_u_interp, ...
plots_v_interp, ...
rois_formatted, ...
int32(border_interp), ...
int32(spacing), ...
int32(num_img-1), ...
int32(total_imgs));

if (outstate_add == out.success)
% Set outputs
plot_added(1) = plot_added_prelim;
outstate = out.success;
end
end
224 changes: 224 additions & 0 deletions ncorr_alg_adddisp.cpp
@@ -0,0 +1,224 @@
// This function adds displacement plots together

#include <mex.h>
#include <math.h>
#include <vector>
#include <list>
#include "standard_datatypes.h"
#include "ncorr_datatypes.h"
#include "ncorr_lib.h"

// ----------------------------------------------------//
// Interp plot input ----------------------------------//
// ----------------------------------------------------//

void get_plot_interp(std::vector<std::vector<class_double_array> > &plot_interp,const mxArray *prhs) {
// Check input - it's a cells containing cells. The outer cell corresponds to the image, while the inner cells correspond to regions
if (mxIsClass(prhs,"cell") && mxGetM(prhs) == 1) {
for (int i=0; i<(int)mxGetN(prhs); i++) {
// Get content of cell corresponding to image number
mxArray *mat_plot_interp_img = mxGetCell(prhs,i);
std::vector<class_double_array> plot_interp_img_template;
if (mat_plot_interp_img != 0 && mxIsClass(mat_plot_interp_img,"cell") && mxGetM(mat_plot_interp_img) == 1) {
for (int j=0; j<(int)mxGetN(mat_plot_interp_img); j++) {
// Get content of cell corresponding to region
mxArray *mat_plot_interp_region = mxGetCell(mat_plot_interp_img,j);
if (mat_plot_interp_region != 0) {
// Form interp plot
class_double_array plot_interp_region_template;
get_double_array(plot_interp_region_template,mat_plot_interp_region);

// Store interp plot per region
plot_interp_img_template.push_back(plot_interp_region_template);
} else {
mexErrMsgTxt("Some cell contents are empty.\n");
}
}
// Store interp plot per img
plot_interp.push_back(plot_interp_img_template);
} else {
mexErrMsgTxt("Some cell contents are empty.\n");
}
}
} else {
mexErrMsgTxt("Interp data must be a row vector of class 'cell'.\n");
}
}

// ----------------------------------------------------//
// Main Class -----------------------------------------//
// ----------------------------------------------------//

class class_adddisp {
public:
// Constructor
class_adddisp(mxArray *plhs [ ],const mxArray *prhs [ ]);

// Methods:
void analysis();

private:
// Properties
// Inputs:
std::vector<std::vector<class_double_array> > plots_u_interp; // local datatype
std::vector<std::vector<class_double_array> > plots_v_interp; // local datatype
std::vector<ncorr_class_roi> rois_interp; // ncorr datatype
int border_interp; // standard datatype
int spacing; // standard datatype
int num_img; // standard datatype
int total_imgs; // standard datatype

// Outputs:
class_double_array plot_u_added;
class_double_array plot_v_added;
class_logical_array plot_validpoints;
double *outstate;

// Other variables:
class_waitbar waitbar;
};

class_adddisp::class_adddisp(mxArray *plhs[ ],const mxArray *prhs[ ]) {
// Get inputs -------------------------------------------------//
// input 1: plots_u_interp
get_plot_interp(plots_u_interp,prhs[0]);
// input 2: plots_v_interp
get_plot_interp(plots_v_interp,prhs[1]);
// input 3: rois_interp - used for determining bounds when forward propagating
get_rois(rois_interp,prhs[2]);
// input 4: border_interp
get_integer_scalar(border_interp,prhs[3]);
// input 5: spacing
get_integer_scalar(spacing,prhs[4]);
// input 6: num_img
get_integer_scalar(num_img,prhs[5]);
// input 7: total_imgs
get_integer_scalar(total_imgs,prhs[6]);

// Check inputs - check sizes - UPDATE THIS LATER!!!!!

// Form/set outputs -------------------------------------------//
// output 1: plot_adddisp
// Form deformation structure
mwSize def_dims[2] = {1,1};
int def_numfields = 3;
const char *def_fieldnames[] = {"plot_u_added","plot_v_added","plot_validpoints"};
plhs[0] = mxCreateStructArray(2, def_dims, def_numfields, def_fieldnames);

// Form fields
mxArray *mat_plot_u_added = mxCreateDoubleMatrix(rois_interp[0].mask.height, rois_interp[0].mask.width, mxREAL);
mxArray *mat_plot_v_added = mxCreateDoubleMatrix(rois_interp[0].mask.height, rois_interp[0].mask.width, mxREAL);
mxArray *mat_plot_validpoints = mxCreateLogicalMatrix(rois_interp[0].mask.height, rois_interp[0].mask.width);

// Add fields to structure
// Add u:
mxSetFieldByNumber(plhs[0],0,0,mat_plot_u_added);
// Add v:
mxSetFieldByNumber(plhs[0],0,1,mat_plot_v_added);
// Add valid points:
mxSetFieldByNumber(plhs[0],0,2,mat_plot_validpoints);

// output 2: outstate
plhs[1] = mxCreateDoubleMatrix(1,1,mxREAL);

// Get outputs -----------------------------------------------//
// output 1: plot_adddisp
// u:
get_double_array(plot_u_added,mat_plot_u_added);
// v:
get_double_array(plot_v_added,mat_plot_v_added);
// plot_validpoints
get_logical_array(plot_validpoints,mat_plot_validpoints);
// output 2: outstate
outstate = mxGetPr(plhs[1]);
}

// ----------------------------------------------------//
// Main Class Methods ---------------------------------//
// ----------------------------------------------------//

void class_adddisp::analysis() {
// Initialize outstate to cancelled
*outstate = (double)CANCELLED;

// Set up waitbar ----------------------------------------------//
int computepoints = 0;
for (int i=0; i<(int)rois_interp[0].region.size(); i++) {
computepoints += rois_interp[0].region[i].totalpoints;
}
waitbar.start(num_img,total_imgs,computepoints);

// Cycle over each region in the first ROI
for (int i=0; i<(int)rois_interp[0].region.size(); i++) {
// Cycle over each point in each region in the first ROI
for (int j=0; j<rois_interp[0].region[i].noderange.height; j++) {
int x_ref_reduced = j+rois_interp[0].region[i].leftbound;
for (int k=0; k<rois_interp[0].region[i].noderange.value[j]; k+=2) {
for (int m=rois_interp[0].region[i].nodelist.value[j+k*rois_interp[0].region[i].nodelist.height]; m<=rois_interp[0].region[i].nodelist.value[j+(k+1)*rois_interp[0].region[i].nodelist.height]; m++) {
int y_ref_reduced = m;

// For each point (x,y), forward propagate this point
// by using the bspline coefficients corresponding to i
bool propsuccess = true; // Set this to false if the point cant be propagated

// Cycle over each plot and propagate until finished
double x_cur_reduced = (double)x_ref_reduced;
double y_cur_reduced = (double)y_ref_reduced;
double u_interp = 0;
double v_interp = 0;
double u_interp_buf = 0;
double v_interp_buf = 0;
for (int n=0; n<(int)rois_interp.size(); n++) {
// Get interpolated u and v displacement values
if (plots_u_interp[n][i].height > 0 && plots_u_interp[n][i].width > 0 && plots_v_interp[n][i].height > 0 && plots_v_interp[n][i].width > 0 &&
interp_qbs(u_interp_buf,x_cur_reduced,y_cur_reduced,plots_u_interp[n][i],rois_interp[n].mask,rois_interp[n].region[i].leftbound,rois_interp[n].region[i].upperbound,border_interp) == SUCCESS &&
interp_qbs(v_interp_buf,x_cur_reduced,y_cur_reduced,plots_v_interp[n][i],rois_interp[n].mask,rois_interp[n].region[i].leftbound,rois_interp[n].region[i].upperbound,border_interp) == SUCCESS) {
// Update displacements
u_interp += u_interp_buf;
v_interp += v_interp_buf;

// Update x_cur and y_cur
x_cur_reduced += u_interp_buf/(spacing+1);
y_cur_reduced += v_interp_buf/(spacing+1);
} else {
propsuccess = false;
break;
}
}

// If point was successfully propagated then store it
if (propsuccess) {
// Store final u_interp and v_interp value
plot_u_added.value[y_ref_reduced + x_ref_reduced*plot_u_added.height] = u_interp;
plot_v_added.value[y_ref_reduced + x_ref_reduced*plot_v_added.height] = v_interp;

// Set this is a valid point
plot_validpoints.value[y_ref_reduced + x_ref_reduced*plot_validpoints.height] = true;
}

// Update, check, and increment waitbar
if (!waitbar.updateandcheck()) {
// Waitbar was cancelled
return;
}
waitbar.increment();
}
}
}
}

// At this point analysis has been completed successfully
*outstate = (double)SUCCESS;
}

void mexFunction(int nlhs,mxArray *plhs[ ],int nrhs,const mxArray *prhs[ ]) {
if (nrhs == 7 && nlhs == 2) {
// Creat adddisp
class_adddisp adddisp(plhs,prhs);

// Run analysis
adddisp.analysis();
} else {
mexErrMsgTxt("Incorrect number of inputs.\n");
}
}

0 comments on commit d0705d7

Please sign in to comment.