|
a |
|
b/Thoracic Organs Segmentation code/OpticalFlow3D/QUIVERdisplay.cpp |
|
|
1 |
#include <mex.h> |
|
|
2 |
#include <mat.h> |
|
|
3 |
#include <matrix.h> |
|
|
4 |
|
|
|
5 |
#define cimg_plugin "cimgmatlab.h" |
|
|
6 |
|
|
|
7 |
#include "CImg.h" |
|
|
8 |
#include <iostream> |
|
|
9 |
#include <string> |
|
|
10 |
|
|
|
11 |
using namespace cimg_library; |
|
|
12 |
using namespace std; |
|
|
13 |
|
|
|
14 |
// The lines below are necessary when using a non-standard compiler as visualcpp6. |
|
|
15 |
#ifdef cimg_use_visualcpp6 |
|
|
16 |
#define std |
|
|
17 |
#endif |
|
|
18 |
#ifdef min |
|
|
19 |
#undef min |
|
|
20 |
#undef max |
|
|
21 |
#endif |
|
|
22 |
|
|
|
23 |
#ifndef cimg_imagepath |
|
|
24 |
#define cimg_imagepath "img/" |
|
|
25 |
#endif |
|
|
26 |
|
|
|
27 |
//global constants |
|
|
28 |
|
|
|
29 |
const bool normalize = true; //"Histogram normalization of the images" |
|
|
30 |
const bool morph = true;//"Morphing mode" |
|
|
31 |
const bool imode = true;//"Complete interpolation (or last frame is missing)" |
|
|
32 |
const bool dispflag = true;//"Visualization" |
|
|
33 |
|
|
|
34 |
|
|
|
35 |
///////////////////////////////////////////////////////////////////////////////// |
|
|
36 |
//Function Prototype |
|
|
37 |
template<typename T> CImg<T> getwarp(const CImg<T>& src, const CImg<>& u); |
|
|
38 |
|
|
|
39 |
|
|
|
40 |
|
|
|
41 |
//mex function |
|
|
42 |
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { |
|
|
43 |
if (nrhs < 2) mexErrMsgTxt("No enough input arguments."); |
|
|
44 |
if (nrhs > 2) mexErrMsgTxt("Too many input arguments."); |
|
|
45 |
if (nrhs == 2){ |
|
|
46 |
CImg<> src(prhs[0],true), u(prhs[1],false); |
|
|
47 |
|
|
|
48 |
//Input images preprocessing |
|
|
49 |
CImg<> src_blur(src.size()); |
|
|
50 |
src_blur = normalize?src.get_blur(0.5f).equalize(256):src.get_blur(0.5f); |
|
|
51 |
|
|
|
52 |
CImgDisplay disp(src_blur); |
|
|
53 |
|
|
|
54 |
if (dispflag) { |
|
|
55 |
unsigned int w = src.dimx(), h = src.dimy(); |
|
|
56 |
const unsigned int dmin = cimg::min(w,h), minsiz = 512; |
|
|
57 |
if (dmin<minsiz) { w=w*minsiz/dmin; h=h*minsiz/dmin; } |
|
|
58 |
const unsigned int dmax = cimg::max(w,h), maxsiz = 1024; |
|
|
59 |
if (dmax>maxsiz) { w=w*maxsiz/dmax; h=h*maxsiz/dmax; } |
|
|
60 |
disp.assign(w,h,"Estimated Motion",0); |
|
|
61 |
} |
|
|
62 |
|
|
|
63 |
CImg<> c = src_blur.get_pointwise_norm(1).resize(src.dimx(),src.dimy()).normalize(0,180); |
|
|
64 |
c.display(disp); |
|
|
65 |
// disp.wait(); |
|
|
66 |
|
|
|
67 |
const unsigned char white = 255; |
|
|
68 |
c.draw_quiver(u,&white,0.7f,10,-14,0).display(disp); |
|
|
69 |
disp.wait(); |
|
|
70 |
|
|
|
71 |
|
|
|
72 |
} |
|
|
73 |
return; |
|
|
74 |
|
|
|
75 |
} |
|
|
76 |
|
|
|
77 |
// get_warp() : Return the image src warped by the motion field u. |
|
|
78 |
//------------ |
|
|
79 |
template<typename T> CImg<T> getwarp(const CImg<T>& src, const CImg<>& u) { |
|
|
80 |
CImg<T> warp(src); |
|
|
81 |
cimg_forXY(warp,x,y) warp(x,y) = (T)src.linear_atXY(x - u(x,y,0), y - u(x,y,1)); |
|
|
82 |
return warp; |
|
|
83 |
} |