1#ifndef __JBXL_CPP_GRAPHIC_MATH_H_
2#define __JBXL_CPP_GRAPHIC_MATH_H_
62 R da, db, dc, dd, de, df, dg, dh;
78 for (j=1; j<vp.
ys-1; j++) {
80 for (i=1; i<vp.
xs-1; i++) {
82 da = vp.
gp[nx+1] + vp.
gp[nx-1];
84 dc = vp.
gp[nx+xs] + vp.
gp[nx-xs];
85 lp.
gp[nx] = (R)(da - 4.*db + dc);
95 for (j=1; j<vp.
ys-1; j++) {
97 for (i=1; i<vp.
xs-1; i++) {
99 da = vp.
gp[nx+1] + vp.
gp[nx-1];
100 db = vp.
gp[nx+xs] + vp.
gp[nx-xs];
102 dd = vp.
gp[nx+1+xs] + vp.
gp[nx-1+xs];
103 de = vp.
gp[nx+1-xs] + vp.
gp[nx-1-xs];
104 lp.
gp[nx] = (R)(da + db - 8.*dc + dd + de);
116 for (j=2; j<vp.
ys-2; j++) {
118 for (i=2; i<vp.
xs-2; i++) {
121 db = vp.
gp[nx+1] + vp.
gp[nx-1] + vp.
gp[nx+xs] + vp.
gp[nx-xs];
122 dc = vp.
gp[nx-1-xs2] + vp.
gp[nx-xs2] + vp.
gp[nx+1-xs2];
123 dd = vp.
gp[nx-1+xs2] + vp.
gp[nx+xs2] + vp.
gp[nx+1+xs2];
124 de = vp.
gp[nx-2-xs ] + vp.
gp[nx-2] + vp.
gp[nx-2+xs];
125 df = vp.
gp[nx+2-xs ] + vp.
gp[nx+2] + vp.
gp[nx+2+xs];
126 dg = vp.
gp[nx-2-xs2] + vp.
gp[nx+2-xs2];
127 dh = vp.
gp[nx-2+xs2] + vp.
gp[nx+2+xs2];
128 lp.
gp[nx] = (R)((-12.*da - 4.*db + 2.*(dc+dd+de+df) + dg + dh)/32.);
158 R da, db, dc, dd, de, nr;
173 if (vcounter!=NULL) vcounter->
SetMax(vp.
zs);
176 for (k=0; k<vp.
zs; k++) {
178 for (j=1; j<vp.
ys-1; j++) {
180 for (i=1; i<vp.
xs-1; i++) {
182 da = vp.
gp[nx+1-vp.
xs] - vp.
gp[nx-1-vp.
xs];
183 db = vp.
gp[nx+1] - vp.
gp[nx-1];
184 dc = vp.
gp[nx+1+vp.
xs] - vp.
gp[nx-1+vp.
xs];
189 if (k==0 || k==vp.
zs-1) {
194 dd = vp.
gp[nx+1-pl] - vp.
gp[nx-1-pl];
195 de = vp.
gp[nx+1+pl] - vp.
gp[nx-1+pl];
201 xp.
gp[nx] = (R)((da + 2.*db + dc + dd + de)/nr);
204 if (vcounter!=NULL) vcounter->
StepIt();
223 R da, db, dc, dd, de, nr;
238 if (vcounter!=NULL) vcounter->
SetMax(vp.
zs);
241 for (k=0; k<vp.
zs; k++) {
243 for (j=1; j<vp.
ys-1; j++) {
245 for (i=1; i<vp.
xs-1; i++) {
247 da = vp.
gp[nx-1+vp.
xs] - vp.
gp[nx-1-vp.
xs];
248 db = vp.
gp[nx +vp.
xs] - vp.
gp[nx -vp.
xs];
249 dc = vp.
gp[nx+1+vp.
xs] - vp.
gp[nx+1-vp.
xs];
254 if (k==0 || k==vp.
zs-1) {
259 dd = vp.
gp[nx+vp.
xs-pl] - vp.
gp[nx-vp.
xs-pl];
260 de = vp.
gp[nx+vp.
xs+pl] - vp.
gp[nx-vp.
xs+pl];
266 xp.
gp[nx] = (R)((da + 2.*db + dc + dd + de)/nr);
269 if (vcounter!=NULL) vcounter->
StepIt();
288 R da, db, dc, dd, de;
307 if (vcounter!=NULL) vcounter->
SetMax(vp.
zs-1);
310 for (k=1; k<vp.
zs-1; k++) {
312 for (j=1; j<vp.
ys-1; j++) {
314 for (i=1; i<vp.
xs-1; i++) {
316 da = vp.
gp[nx-1+pl] - vp.
gp[nx-1-pl];
317 db = vp.
gp[nx+1+pl] - vp.
gp[nx+1-pl];
318 dc = vp.
gp[nx +pl] - vp.
gp[nx -pl];
319 dd = vp.
gp[nx-vp.
xs+pl] - vp.
gp[nx-vp.
xs-pl];
320 de = vp.
gp[nx+vp.
xs+pl] - vp.
gp[nx+vp.
xs-pl];
326 xp.
gp[nx] = (R)((da + db + 2.*dc + dd + de)/12.);
329 if (vcounter!=NULL) vcounter->
StepIt();
334 for (j=1; j<vp.
ys-1; j++) {
336 for (i=1; i<vp.
xs-1; i++) {
340 dc = vp.
gp[nx+1 +pl] + vp.
gp[nx-1 +pl];
341 dd = vp.
gp[nx+vp.
xs+pl] + vp.
gp[nx-vp.
xs+pl];
346 xp.
gp[nx] = (R)((2.*db + dc + dd)/6. - da);
350 for (i=1; i<vp.
xs-1; i++) {
354 dc = vp.
gp[nx+1 -pl] + vp.
gp[nx-1 -pl];
355 dd = vp.
gp[nx+vp.
xs-pl] + vp.
gp[nx-vp.
xs-pl];
360 xp.
gp[nx] = (R)(da - (2.*db + dc + dd)/6.);
363 if (vcounter!=NULL) vcounter->
PutFill();
380 int pl, nx, ny, nz, pl2, xs, xs2;
381 R da, db, dc, dd, de;
382 R df, dg, dh, di, dj, dk, dl, dm, nr;
397 if (vcounter!=NULL) vcounter->
SetMax(vp.
zs);
404 for (k=0; k<vp.
zs; k++) {
406 for (j=2; j<vp.
ys-2; j++) {
408 for (i=2; i<vp.
xs-2; i++) {
410 da = vp.
gp[nx+2-xs2] - 2*vp.
gp[nx-xs2] + vp.
gp[nx-2-xs2];
411 db = vp.
gp[nx+2-xs ] - 2*vp.
gp[nx-xs] + vp.
gp[nx-2-xs];
412 dc = vp.
gp[nx+2] - 2*vp.
gp[nx] + vp.
gp[nx-2];
413 dd = vp.
gp[nx+2+xs] - 2*vp.
gp[nx+xs] + vp.
gp[nx-2+xs];
414 de = vp.
gp[nx+2+xs2] - 2*vp.
gp[nx+xs2] + vp.
gp[nx-2+xs2];
421 if (k==0 || k==vp.
zs-1) {
423 df = dg = dh = di = dj = dk = dl = dm = 0;
428 df = vp.
gp[nx+2-xs-pl] - 2*vp.
gp[nx-xs-pl] + vp.
gp[nx-2-xs-pl];
429 dg = vp.
gp[nx+2 -pl] - 2*vp.
gp[nx -pl] + vp.
gp[nx-2 -pl];
430 dh = vp.
gp[nx+2+xs-pl] - 2*vp.
gp[nx+xs-pl] + vp.
gp[nx-2+xs-pl];
431 di = vp.
gp[nx+2-xs+pl] - 2*vp.
gp[nx-xs+pl] + vp.
gp[nx-2-xs+pl];
432 dj = vp.
gp[nx+2 +pl] - 2*vp.
gp[nx +pl] + vp.
gp[nx-2 +pl];
433 dk = vp.
gp[nx+2+xs+pl] - 2*vp.
gp[nx+xs+pl] + vp.
gp[nx-2+xs+pl];
441 if (k==1 || k==vp.
zs-2) {
446 dl = vp.
gp[nx+2-pl2] - 2*vp.
gp[nx-pl2] + vp.
gp[nx-2-pl2];
447 dm = vp.
gp[nx+2+pl2] - 2*vp.
gp[nx+pl2] + vp.
gp[nx-2+pl2];\
453 xp.
gp[nx] = (R)((dc + 4.*(db+dd+dg+dj) + 2.*(df+dh+di+dk) + da+de+dl+dm)/nr);
456 if (vcounter!=NULL) vcounter->
StepIt();
473 int pl, nx, ny, nz, pl2, xs, xs2;
474 R da, db, dc, dd, de;
475 R df, dg, dh, di, dj, dk, dl, dm, nr;
490 if (vcounter!=NULL) vcounter->
SetMax(vp.
zs);
497 for (k=0; k<vp.
zs; k++) {
499 for (j=2; j<vp.
ys-2; j++) {
501 for (i=2; i<vp.
xs-2; i++) {
503 da = vp.
gp[nx-2+xs2] - 2*vp.
gp[nx-2] + vp.
gp[nx-2-xs2];
504 db = vp.
gp[nx-1+xs2] - 2*vp.
gp[nx-1] + vp.
gp[nx-1-xs2];
505 dc = vp.
gp[nx +xs2] - 2*vp.
gp[nx] + vp.
gp[nx -xs2];
506 dd = vp.
gp[nx+1+xs2] - 2*vp.
gp[nx+1] + vp.
gp[nx+1-xs2];
507 de = vp.
gp[nx+2+xs2] - 2*vp.
gp[nx+2] + vp.
gp[nx+2-xs2];
514 if (k==0 || k==vp.
zs-1) {
516 df = dg = dh = di = dj = dk = dl = dm = 0;
521 df = vp.
gp[nx-1+xs2-pl] - 2*vp.
gp[nx-1-pl] + vp.
gp[nx-1-xs2-pl];
522 dg = vp.
gp[nx +xs2-pl] - 2*vp.
gp[nx -pl] + vp.
gp[nx -xs2-pl];
523 dh = vp.
gp[nx+1+xs2-pl] - 2*vp.
gp[nx+1-pl] + vp.
gp[nx+1-xs2-pl];
524 di = vp.
gp[nx-1+xs2+pl] - 2*vp.
gp[nx-1+pl] + vp.
gp[nx-1-xs2+pl];
525 dj = vp.
gp[nx +xs2+pl] - 2*vp.
gp[nx +pl] + vp.
gp[nx -xs2+pl];
526 dk = vp.
gp[nx+1+xs2+pl] - 2*vp.
gp[nx+1+pl] + vp.
gp[nx+1-xs2+pl];
534 if (k==1 || k==vp.
zs-2) {
539 dl = vp.
gp[nx+xs2-pl2] - 2*vp.
gp[nx-pl2] + vp.
gp[nx-xs2-pl2];
540 dm = vp.
gp[nx+xs2+pl2] - 2*vp.
gp[nx+pl2] + vp.
gp[nx-xs2+pl2];
546 xp.
gp[nx] = (R)((dc + 4.*(db+dd+dg+dj) + 2.*(df+dh+di+dk) + da+de+dl+dm)/nr);
549 if (vcounter!=NULL) vcounter->
StepIt();
567 R da, db, dc, dd, de;
568 R df, dg, dh, di, dj, dk, dl, dm;
581 if (vcounter!=NULL) {
589 if (vcounter!=NULL) {
601 if (vcounter!=NULL) {
662 for (i=0; i<vp.
xs*vp.
ys*vp.
zs; i++) {
687 for (i=0; i<vp.
xs*vp.
ys*vp.
zs; i++) {
688 (nv.
gp[i])->set_Vector(px.
gp[i], py.
gp[i], pz.
gp[i]);
741 for (i=0; i<vp.
xs*vp.
ys*vp.
zs; i++) {
745 nv.
gp[i] = (R)sqrt((
double)xx*xx + yy*yy + zz*zz);
780 la = Laplacian<R>(gd, mode);
781 for (i=0; i<vp.
xs*vp.
ys*vp.
zs; i++) {
782 vp.
gp[i] = gd.
gp[i] - la.
gp[i];
802 int i, j, x, y, z, cx;
803 int xx, yy, zz, cw, ux, mz;
804 int kc, xc, zc, xs, ps;
809 me = (T*)malloc(ms*ms*mz*
sizeof(T));
810 if (me!=NULL) memset(me, 0, ms*ms*mz*
sizeof(T));
826 for(y=xc; y<xp.
ys-xc; y++)
827 for(x=xc; x<xp.
xs-xc; x++) {
828 cx = z*ps + y*xs + x;
830 for (zz=-zc; zz<=zc; zz++)
831 for (yy=-xc; yy<=xc; yy++)
832 for (xx=-xc; xx<=xc; xx++) {
833 cw = cx + xx + yy*xs + zz*ps;
836 for (i=0; i<ms*ms*mz-1; i++)
837 for (j=i+1; j<ms*ms*mz; j++) {
844 vp.
gp[cx-z*ps] = me[kc];
866 int i, j, k, l, df, d, w;
867 int rmax, rstart, rend;
878 for (i=0; i<vp.
xs*vp.
ys*vp.
zs; i++) {
879 if (vp.
gp[i]>=bc) pp.
gp[i] = 1;
885 for (k=0; k<vp.
zs; k++) {
887 for (j=0; j<vp.
ys; j++) {
890 for (i=0; i<vp.
xs; i++) {
892 if (pp.
gp[nx]!=0) df = df + 1;
899 for (k=0; k<vp.
zs; k++) {
901 for (j=0; j<vp.
ys; j++) {
904 for (i=vp.
xs-1; i>=0; i--) {
906 if (pp.
gp[nx]!=0) df = df + 1;
908 pp.
gp[nx] =
Min(pp.
gp[nx], df*df);
922 for (k=0; k<vp.
zs; k++) {
924 for (i=0; i<vp.
xs; i++) {
926 for (j=0; j<vp.
ys; j++) buf.
gp[j] = pp.
gp[nx+j*vp.
xs];
927 for (j=0; j<vp.
ys; j++) {
931 rmax = (int)sqrt((
double)d) + 1;
932 rstart =
Min(rmax, j);
933 rend =
Min(rmax, vp.
ys-j-1);
934 for (l=-rstart; l<=rend; l++) {
935 w = buf.
gp[j+l] + l*l;
946 for (j=0; j<vp.
ys; j++) {
948 for (i=0; i<vp.
xs; i++) {
950 for (k=0; k<vp.
zs; k++) buf.
gp[k] = pp.
gp[nx+k*pl];
951 for (k=0; k<vp.
zs; k++) {
955 rmax = (int)sqrt((
double)d) + 1;
956 rstart =
Min(rmax, k);
957 rend =
Min(rmax, vp.
zs-k-1);
958 for (l=-rstart; l<=rend; l++) {
959 w = buf.
gp[k+l] + l*l;
981#define FILTER_MINMAX 2
992 if (vp.
xs<filter.
xs || vp.
ys<filter.
ys || vp.
zs<filter.
zs) {
997 if (filter.
norm==0.0) {
1005 int xs = filter.
xs/2;
1006 int ys = filter.
ys/2;
1007 int zs = filter.
zs/2;
1009 for (
int k=zs; k<xp.
zs-zs; k++) {
1010 for (
int j=ys; j<xp.
ys-ys; j++) {
1011 for (
int i=xs; i<xp.
xs-xs; i++) {
1014 for (
int n=-zs; n<=zs; n++) {
1015 for (
int m=-ys; m<=ys; m++) {
1016 for (
int l=-xs; l<=xs; l++) {
1017 conv += filter.
point(xs+l, ys+m, zs+n) * vp.
point(i+l, j+m, k+n);
1022 R pt = (R)(conv/filter.
norm);
1026 if (pt<(R)vp.
min) pt = (R)vp.
min;
1027 else if (pt>(R)vp.
max) pt = (R)vp.
max;
1029 xp.
point(i, j, k) = pt;
1036 for (
int i=0; i<xp.
xs*xp.
ys*xp.
zs; i++) {
#define FILTER_MINMAX
元のデータの範囲に限定
#define FILTER_NORM
元のデータの範囲に伸張
virtual void StepIt(int n=1)
カウンタのメモリを増やす
virtual void SetMax(int m)
カウンタの最大値(最終目標)を設定
virtual void DeleteChildCounter()
子カウンタの削除(有効領域の無効化)
virtual CVCounter * MakeChildCounter(int n)
子カウンタの作成(有効領域を再定義)
virtual void PutFill()
取り敢えずの目標(最短目標)までカウンタを進める.
void clear(T v)
全空間を画素値 v にする
T & point(int x, int y=0, int z=0)
座標(x,y,z)の画素値の参照
int zs
zサイズ. 4Byte. 2Dの場合は 1.
void get_minmax(void)
min, max を獲得
double norm
規格化定数.フィルタのときに使用.
double RZxy
Z軸の歪.Z軸の間隔を 1とした XY軸の間隔.(X or Y)/Z.
void free(void)
グラフィックデータを開放する
bool isNull(void)
グラフィックデータを持っていないか?
void mimicry(MSGraph< R > s)
RBound< int > rbound
画像の境界情報
#define JBXL_GRAPH_NODATA_ERROR
データが無い
#define JBXL_GRAPH_MEMORY_ERROR
メモリエラー
MSGraph< R > Laplacian(MSGraph< T > vp, int mode=0)
CVCounter * GetUsableGlobalCounter()
現在有効なグローバルカウンタを得る.(子カウンタを得るかもしれない)
MSGraph< int > euclidDistance(MSGraph< T > vp, int bc, int &rr)
MSGraph< R > xSobel(MSGraph< T > vp)
MSGraph< R > xxSobel(MSGraph< T > vp)
MSGraph< R > edgeEnhance(MSGraph< T > gd, int mode=0)
MSGraph< R > ySobel(MSGraph< T > vp)
MSGraph< R > zzSobel(MSGraph< T > vp)
void SetGlobalCounter(CVCounter *counter)
グローバルカウンタのセット
MSGraph< R > MSMaskFilter(MSGraph< R > vp, MSGraph< T > filter, int mode=FILTER_NON)
MSGraph< R > zSobel(MSGraph< T > vp)
MSGraph< Vector< R > > vNabla(MSGraph< T > vp)
MSGraph< T > medianFilter(MSGraph< T > xp, int ms=3)
MSGraph< R > Nabla(MSGraph< T > vp)
MSGraph< R > yySobel(MSGraph< T > vp)