-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathcomputecontrast5.cpp
More file actions
96 lines (85 loc) · 2.24 KB
/
Copy pathcomputecontrast5.cpp
File metadata and controls
96 lines (85 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// #include <windows.h>
// #include <stdlib.h>
// #include <stdio.h>
#include <string.h>
// #include "engine.h"
#include <mex.h>
#include<malloc.h>
#include<math.h>
using namespace std;
void img_extract(double *img_patch,const mxArray *ori_image,int startrow,int startcol, int length)
{
//mxArray *img_patch=NULL;
int orirow,oricol;
int j;
double *imgpoint;
//img_patch = mxCreateDoubleMatrix(length, length, mxREAL);
orirow = (int)mxGetM(ori_image);
oricol = (int)mxGetN(ori_image);
//patpoint = mxGetPr(img_patch);
imgpoint = mxGetPr(ori_image);
for (j=1;j<=length;j++)
{
memcpy((img_patch+(j-1)*length), (imgpoint+(startcol+j-2)*orirow+startrow-1), length*sizeof(double));
}
// return img_patch;
}
void outer_pro(double *out,double *a,double *b,int length)
{
int i;
// double *out;
// out=(double *)malloc(length*sizeof(double));
for(i=1;i<=length;i++)
{
*(out+i-1)=(*(a+i-1))*(*(b+i-1));
}
}
double sumup(double *a,int length)
{
double out=0;
int i;
for(i=1;i<=length;i++)
{
out=out+*(a+i-1);
}
return out;
}
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
double *temp_patch,*temp1,*my_maskPoint,*finPoint,*salmap;
mxArray *my_image=NULL;
int m,n,len,winsize,m1,n1;
int row,col,i;
double patch_mean,temp2;
// my_image=prhs[0];
my_maskPoint=mxGetPr(prhs[1]);
m=(int)*(mxGetPr(prhs[4]));
n=(int)*(mxGetPr(prhs[5]));
m1 = mxGetM(prhs[0]);
n1 = mxGetN(prhs[0]);
len=(int)*(mxGetPr(prhs[2]));
winsize=(int)*(mxGetPr(prhs[3]));
salmap=mxGetPr(prhs[0]);
//invalid_ind=mxGetPr(prhs[5]);
temp_patch=(double *)malloc(winsize*winsize*sizeof(double));
temp1=(double *)malloc(winsize*winsize*sizeof(double));
plhs[0] = mxCreateDoubleMatrix(m, n, mxREAL);
finPoint = mxGetPr(plhs[0]);
for(row=1+len;row<=m+len;row++)
{
for(col=1+len;col<=n+len;col++)
{
img_extract(temp_patch,prhs[0],row-len,col-len,winsize);
// outer_pro(temp1,temp_patch,my_maskPoint,winsize*winsize);
patch_mean=*(salmap+(col-1)*m1+row-1);
for (i=1;i<=winsize*winsize;i++)
{
if(*(temp_patch+i-1)!=0)
*(temp_patch+i-1)=abs(*(temp_patch+i-1)-patch_mean);
}
outer_pro(temp1,temp_patch,my_maskPoint,winsize*winsize);
temp2=sumup(temp1,winsize*winsize);
*(finPoint+(col-len-1)*m+row-len-1)=temp2;
}
}
}