c/4713: syntax error on #include commands
dllau@engr.uky.edu
dllau@engr.uky.edu
Sat Oct 27 14:16:00 GMT 2001
>Number: 4713
>Category: c
>Synopsis: syntax error on #include commands
>Confidential: no
>Severity: serious
>Priority: high
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sat Oct 27 14:15:59 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator: Dr. Daniel L. Lau
>Release: 2.95.2 200002200 (Debian/GNU Linux)
>Organization:
>Environment:
PC running Linux
>Description:
bippcca: #include expects "FILENAME" or <FILENAME>
>How-To-Repeat:
just run using the gcc bippcca.c command
>Fix:
don't have one yet
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="bippcca.c"
Content-Disposition: inline; filename="bippcca.c"
/****************************************************************************************/
/* */
/* Daniel Leo Lau */
/* Copyright February 14, 1998 */
/* */
/****************************************************************************************/
#include <stdlib.h>
#include <math.h>
#include "mex.h"
#define pi 3.14159265358979
#define TOL 1e-32
#define max_num_pts 65536
double *K_data;
double *H_data;
double VAR;
int image_row;
int image_col;
int K_flag;
int H_flag;
int num_K_points;
int num_H_points;
int tot_num_ones;
int max_pixel_list[max_num_pts];
int num_pixels_in_list;
typedef struct {
double row;
double col;
double cost;
double angle;
double fr;
} cost_array_node;
/********************************************************************************/
/* */
/********************************************************************************/
double interp(double *Fx, double *x, int length_list, double s)
{
int m;
double slope;
for (m=0; m<length_list-1; m++){
if ((x[m]<=s)&&(x[m+1]>s)){
slope=(Fx[m]-Fx[m+1])/(x[m]-x[m+1]);
return(Fx[m]+slope*(s-x[m]));
}
}
return(1.0);
}
/********************************************************************************/
/* */
/********************************************************************************/
void hpsort_cost_array(int n, cost_array_node *ra)
{
int i, ir, j, l;
cost_array_node rra;
if (n<2) return;
l=(n >> 1)+1;
ir=n;
for( ; ; ){
if (l>1){
--l;
rra=ra[l-1];
}
else {
rra=ra[ir-1];
ra[ir-1]=ra[0];
if (--ir==1){
ra[0]=rra;
break;
}
}
i=l;
j=l+l;
while(j<=ir){
if (j < ir && ra[j-1].cost < ra[j].cost)j++;
if (rra.cost < ra[j-1].cost){
ra[i-1]=ra[j-1];
i=j;
j<<=1;
}
else j=ir+1;
}
ra[i-1]=rra;
}
return;
}
/********************************************************************************/
/* */
/********************************************************************************/
int find_max_pixel(double *cost_matrix)
{
int m;
double K, *pr;
mxArray *array_ptr, *input_array[1];
num_pixels_in_list=0;
for (m=0; m<image_row*image_col; m++){
if (cost_matrix[m]>TOL){
if (num_pixels_in_list==0){
num_pixels_in_list=1;
max_pixel_list[0]=m;
}
else if (cost_matrix[m]>cost_matrix[max_pixel_list[0]]){
num_pixels_in_list=1;
max_pixel_list[0]=m;
}
else if (cost_matrix[m]==cost_matrix[max_pixel_list[0]]){
max_pixel_list[num_pixels_in_list++]=m;
if (num_pixels_in_list==max_num_pts) num_pixels_in_list=1;
}
}
}
if (num_pixels_in_list==0){
array_ptr = mxCreateDoubleMatrix(image_row, image_col, mxREAL);
pr=mxGetPr(array_ptr);
input_array[0]=array_ptr;
for (m=0; m<image_row*image_col; m++){
pr[m]=cost_matrix[m];
}
mxSetName(array_ptr, "cost_matrix");
mexPutArray(array_ptr, "base");
mexErrMsgTxt("ERROR CODE 0: Improper pair correlation shaping function!");
}
m=max_pixel_list[(int)floor((double)rand()/(double)RAND_MAX*(double)num_pixels_in_list)];
return(m);
}
/********************************************************************************/
/* */
/********************************************************************************/
void create_cost_array0(cost_array_node **cost_array)
{
int i, j, m, n, index;
m=-image_row/2+1;
n=-image_col/2+1;
for (j=0; j<image_col; j++){
for (i=0; i<image_row; i++){
index=i+j*image_row;
(*cost_array)[index].row=m+i;
(*cost_array)[index].col=n+j;
}
}
return;
}
/********************************************************************************/
/* */
/********************************************************************************/
void create_cost_array1(cost_array_node **cost_array)
{
int i,j,m,n, index;
double d, *pr, ang;
mxArray *array_ptr;
array_ptr = mxCreateDoubleMatrix(image_row, image_col, mxREAL);
pr=mxGetPr(array_ptr);
m=-image_row/2+1;
n=-image_col/2+1;
for (j=0; j<image_col; j++){
for (i=0; i<image_row; i++){
index=i+j*image_row;
(*cost_array)[index].row=m+i;
(*cost_array)[index].col=n+j;
(*cost_array)[index].cost=sqrt((m+i)*(m+i)+(n+j)*(n+j));
(*cost_array)[index].angle=atan2(-1.0*(m+i), (n+j));
if (K_flag==1)
(*cost_array)[index].fr=interp(&K_data[0], &K_data[num_K_points], num_K_points,
(*cost_array)[index].cost);
else if (K_flag==2)
(*cost_array)[index].fr=K_data[index];
pr[index]=(*cost_array)[index].fr;
}
}
hpsort_cost_array(image_row*image_col, *cost_array);
mxSetName(array_ptr, "shaping_filter1");
mexPutArray(array_ptr, "base");
return;
}
/********************************************************************************/
/* */
/********************************************************************************/
void create_cost_array2(cost_array_node **cost_array)
{
int i,j,m,n,index;
double d, *pr, ang, cost, sum=0.0;
mxArray *array_ptr;
array_ptr = mxCreateDoubleMatrix(image_row, image_col, mxREAL);
pr=mxGetPr(array_ptr);
m=-image_row/2+1;
n=-image_col/2+1;
for (j=0; j<image_col; j++){
for (i=0; i<image_row; i++){
index=i+j*image_row;
(*cost_array)[index].row=m+i;
(*cost_array)[index].col=n+j;
(*cost_array)[index].cost=sqrt((m+i)*(m+i)+(n+j)*(n+j));
(*cost_array)[index].angle=atan2(-1.0*(m+i), (n+j));
if (H_flag==1)
(*cost_array)[index].fr=interp(&H_data[0], &H_data[num_H_points], num_H_points,
(*cost_array)[index].cost);
else if (H_flag==2){
(*cost_array)[index].fr=exp(-1.0 * (*cost_array)[index].cost*
(*cost_array)[index].cost*
(1.0/VAR/VAR));
sum+=(*cost_array)[i+j*image_row].fr;
}
else if (H_flag==3)
(*cost_array)[index].fr=H_data[index];
pr[index]=(*cost_array)[index].fr;
}
}
if (H_flag==2)
for (j=0; j<image_row*image_col; j++){
(*cost_array)[j].fr*=(1.0/sum);
}
hpsort_cost_array(image_row*image_col, *cost_array);
mxSetName(array_ptr, "shaping_filter2");
mexPutArray(array_ptr, "base");
return;
}
/********************************************************************************/
/* */
/********************************************************************************/
int in_list(int M)
{
int m;
for (m=0; m<num_pixels_in_list; m++){
if (max_pixel_list[m]==M) return(1);
}
return(0);
}
/********************************************************************************/
/* */
/********************************************************************************/
void calc_cost_matrix1(double *cost_matrix, cost_array_node *cost_array, int i, int j)
{
int m, x_coor, y_coor, index, k, n;
index=i+j*image_row;
cost_matrix[index]=0.0;
for (m=0; m<image_row*image_col; m++){
x_coor=i+cost_array[m].row;
y_coor=j+cost_array[m].col;
if (x_coor<0) x_coor+=image_row;
else if (x_coor>=image_row) x_coor-=image_row;
if (y_coor<0) y_coor+=image_col;
else if (y_coor>=image_col) y_coor-=image_col;
index=x_coor+y_coor*image_row;
cost_matrix[index]*=cost_array[m].fr;
}
return;
}
/********************************************************************************/
/* */
/********************************************************************************/
void calc_cost_matrix2(double *cost_matrix, cost_array_node *cost_array, int i, int j)
{
int m, x_coor, y_coor, M, k, n;
for (m=0; m<image_row*image_col; m++){
x_coor=i+cost_array[m].row;
y_coor=j+cost_array[m].col;
if (x_coor<0) x_coor+=image_row;
else if (x_coor>=image_row) x_coor-=image_row;
if (y_coor<0) y_coor+=image_col;
else if (y_coor>=image_col) y_coor-=image_col;
M=x_coor+y_coor*image_row;
cost_matrix[M]+=cost_array[m].fr;
}
return;
}
/********************************************************************************/
/* */
/********************************************************************************/
void bippcca(unsigned char *output_image,
unsigned char *input_image,
unsigned char *mask_image)
{
int m, i, j, k=0;
double *cost_matrix1, *cost_matrix2, *cost_matrix3, *pr, pmin, pmax;
cost_array_node *cost_array1, *cost_array2;
mxArray *array_ptr, *output_array[1], *input_array[1];
array_ptr = mxCreateDoubleMatrix(image_row, image_col, mxREAL);
pr=mxGetPr(array_ptr);
input_array[0]=array_ptr;
cost_array1=(cost_array_node*)mxCalloc(image_row*image_col, sizeof(cost_array_node));
create_cost_array1(&cost_array1);
cost_matrix1=(double*)mxCalloc(image_row*image_col, sizeof(double));
if (H_flag!=0){
cost_array2=(cost_array_node*)mxCalloc(image_row*image_col, sizeof(cost_array_node));
create_cost_array2(&cost_array2);
cost_matrix2=(double*)mxCalloc(image_row*image_col, sizeof(double));
cost_matrix3=(double*)mxCalloc(image_row*image_col, sizeof(double));
}
for (m=0; m<image_row*image_col; m++){
if (mask_image[m]==(unsigned char)0){
cost_matrix1[m]=(double)rand()/(double)RAND_MAX;
}
else
cost_matrix1[m]=-1.0;
}
for (i=0; i<image_row; i++){
for (j=0; j<image_col; j++){
if (input_image[i+j*image_row]==1){
output_image[i+j*image_row]=1;
calc_cost_matrix1(cost_matrix1, cost_array1, i, j);
if (H_flag!=0) calc_cost_matrix2(cost_matrix2, cost_array2, i, j);
k++;
}
}
}
while(k<tot_num_ones){
if (H_flag!=0){
pmin=cost_matrix2[0];
pmax=cost_matrix2[0];
for (j=0; j<image_row*image_col; j++){
if (pmin > cost_matrix2[j]) pmin=cost_matrix2[j];
if (pmax < cost_matrix2[j]) pmax=cost_matrix2[j];
}
if (pmax==0)
for (j=0; j<image_row*image_col; j++){
cost_matrix3[j]=cost_matrix1[j];
}
else
for (j=0; j<image_row*image_col; j++){
cost_matrix3[j]=1.0-(cost_matrix2[j]-pmin)/(pmax-pmin);
cost_matrix3[j]*=cost_matrix1[j];
}
m=find_max_pixel(cost_matrix3);
}
else
m=find_max_pixel(cost_matrix1);
i=m%image_row;
j=(m-i)/image_row;
if (mask_image[i+j*image_row]==1){
mexPrintf("M=%d, N=%d, COST=%f\n", i+1, j+1, cost_matrix3[i+j*image_row]);
for (m=0; m<image_row*image_col; m++){
pr[m]=(double)output_image[m];
}
/*mexCallMATLAB(0, output_array, 1, input_array, "imagesc");
mexCallMATLAB(0, output_array, 0, input_array, "drawnow");*/
mxSetName(array_ptr, "cost_matrix");
mexPutArray(array_ptr, "base");
mexErrMsgTxt("ERROR CODE 1!");}
output_image[i+j*image_row]=1;
calc_cost_matrix1(cost_matrix1, cost_array1, i, j);
if (H_flag!=0) calc_cost_matrix2(cost_matrix2, cost_array2, i, j);
k++;
/*for (m=0; m<image_row*image_col; m++){
pr[m]=(double)output_image[m];
}
mexCallMATLAB(0, output_array, 1, input_array, "imagesc");
mexCallMATLAB(0, output_array, 0, input_array, "drawnow");
mxSetName(array_ptr, "cost_matrix");
mexPutArray(array_ptr, "base");*/
}
return;
}
/********************************************************************************/
/* */
/********************************************************************************/
void GetRowColCooridinates(double row_pointer[], double col_pointer[])
{
int m, x_coor, y_coor;
cost_array_node *cost_array;
cost_array=(cost_array_node*)mxCalloc(image_row*image_col, sizeof(cost_array_node));
create_cost_array0(&cost_array);
for (m=0; m<image_row*image_col; m++){
x_coor=cost_array[m].row+image_row/2-1;
y_coor=cost_array[m].col+image_col/2-1;
row_pointer[x_coor+y_coor*image_row]=cost_array[m].row;
col_pointer[x_coor+y_coor*image_row]=cost_array[m].col;
}
return;
}
/********************************************************************************/
/* */
/********************************************************************************/
int mxIsScalar(const mxArray *input_array)
{
return(mxGetM(input_array)==1 && mxGetN(input_array)==1);
}
/********************************************************************************/
/* */
/********************************************************************************/
int mxIsVector(const mxArray *input_array)
{
return((mxGetM(input_array)==1 && mxGetN(input_array)!=1) ||
(mxGetM(input_array)!=1 && mxGetN(input_array)==1));
}
/********************************************************************************/
/* */
/********************************************************************************/
int mxIsMatrix(const mxArray *input_array)
{
return((mxGetM(input_array)!=1 && mxGetN(input_array)!=1));
}
/*******************************************************************************/
/* mexFUNCTION */
/* Gateway routine for use with MATLAB. */
/*******************************************************************************/
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
unsigned char *input_image, *output_image, *mask_image;
double gray_level, *row_pointer, *col_pointer, *image_size_data;
int m, output_dims[2];
/* ENSURE PROPER NUMBER OF ARGUMENTS SPECIFIED */
if (!(nrhs==1 && nlhs==2) &&
!(nrhs==3 && nlhs==1) &&
!(nrhs==4 && nlhs==1) &&
!(nrhs==5 && nlhs==1))
mexErrMsgTxt("Improper number of arguments!");
/* HANDLE THE FIRST INPUT ARGUMENT AS A BINARY IMAGE OR AS A VECTOR */
/* SPECIFYING THE DIMENSIONS OF THE OUTPUT IMAGE */
if (mxIsMatrix(prhs[0])){
if (!mxIsNumeric(prhs[0]) ||
mxIsComplex(prhs[0]) ||
mxIsSparse(prhs[0]) ||
!mxIsUint8(prhs[0]) ||
!mxIsLogical(prhs[0]))
mexErrMsgTxt("Input X must be a real matrix of type uint8 (logical)!");
else {
image_row=mxGetM(prhs[0]);
image_col=mxGetN(prhs[0]);
input_image=(unsigned char*)mxGetPr(prhs[0]);
}
}
else if ((mxGetM(prhs[0])*mxGetN(prhs[0]))==2){
if (!mxIsNumeric(prhs[0]) ||
mxIsComplex(prhs[0]) ||
mxIsSparse(prhs[0]))
mexErrMsgTxt("Input [M N] must be a real vector!");
else {
image_size_data=mxGetPr(prhs[0]);
image_row=(int)image_size_data[0];
image_col=(int)image_size_data[1];
input_image=(unsigned char*)mxCalloc(image_row*image_col, sizeof(unsigned char));
}
}
/* IF ONLY ONE INPUT ARGUMENT IS SPECIFIED ALONG WITH TWO OUTPUT ARGUMENTS */
/* THEN OUTPUT THE ROW AND COLUMN COORIDINATES FOR THE SHAPING FUNCTION */
if (nrhs==1 && nlhs==2){
plhs[0]=mxCreateDoubleMatrix(image_row, image_col, mxREAL);
row_pointer=mxGetPr(plhs[0]);
plhs[1]=mxCreateDoubleMatrix(image_row, image_col, mxREAL);
col_pointer=mxGetPr(plhs[1]);
GetRowColCooridinates(row_pointer, col_pointer);
return;
}
/* SET THE GRAY LEVEL FOR THE RESULTING OUTPUT PATTERN */
if (!mxIsNumeric(prhs[1]) ||
mxIsComplex(prhs[1]) ||
mxIsSparse(prhs[1]) ||
!mxIsScalar(prhs[1]))
mexErrMsgTxt("Input g must be a real scalar!");
else {
gray_level=mxGetScalar(prhs[1]);
if (gray_level<=0)
mexErrMsgTxt("Input g must be greater than 1!");
else if (gray_level < 0.5)
tot_num_ones=(int)floor(image_row*image_col*gray_level+0.5);
else if (gray_level < 1.0 && gray_level >= 0.5)
tot_num_ones=(int)floor(image_row*image_col*(1.0-gray_level)+0.5);
else
tot_num_ones=(int)floor(gray_level);
}
/* SPECIFY THE SHAPING FUNCTION K*/
if (mxGetN(prhs[2])==2){
K_flag=1;
if (!mxIsNumeric(prhs[2]) ||
mxIsComplex(prhs[2]) ||
mxIsSparse(prhs[2]))
mexErrMsgTxt("Input [K, r] must be a real matrix!");
num_K_points=mxGetM(prhs[2]);
K_data=mxGetPr(prhs[2]);
}
else if (mxIsMatrix(prhs[2])){
K_flag=2;
if (!mxIsNumeric(prhs[2]) ||
mxIsComplex(prhs[2]) ||
mxIsSparse(prhs[2]))
mexErrMsgTxt("Input K must be a real matrix of type double!");
if (mxGetM(prhs[2])!=image_row || mxGetN(prhs[2])!=image_col)
mexErrMsgTxt("Input K must be same size as H!");
K_data=mxGetPr(prhs[2]);
}
else mexErrMsgTxt("Input K must be a matrix of type double!");
/* SPECIFY THE STATIONARY FILTER Hlp*/
if (nrhs>3 && !(mxGetN(prhs[3])*mxGetM(prhs[3])==0)){
if (mxGetN(prhs[3])==2 && mxGetM(prhs[3])>1){
H_flag=1;
if (!mxIsNumeric(prhs[3]) ||
mxIsComplex(prhs[3]) ||
mxIsSparse(prhs[3]))
mexErrMsgTxt("Input [Hlp, r] must be a real matrix!");
num_H_points=mxGetM(prhs[2]);
}
else if (mxIsScalar(prhs[3])){
H_flag=2;
if (!mxIsNumeric(prhs[3]) ||
mxIsComplex(prhs[3]) ||
mxIsSparse(prhs[3]))
mexErrMsgTxt("Input Hlp must be a scalar of type double!");
VAR=mxGetScalar(prhs[3]);
}
else if (mxIsMatrix(prhs[3])){
H_flag=3;
if (!mxIsNumeric(prhs[3]) ||
mxIsComplex(prhs[3]) ||
mxIsSparse(prhs[3]))
mexErrMsgTxt("Input Hlp must be a real matrix of type double!");
if (mxGetM(prhs[3])!=image_row || mxGetN(prhs[2])!=image_col)
mexErrMsgTxt("Input Hlp must be same size as H!");
H_data=mxGetPr(prhs[3]);
}
else mexErrMsgTxt("Input Hlp must be a matrix of type double!");
}
else {
H_flag=0;
}
/* SPECIFY THE MASK M */
if (nrhs==5){
if (!mxIsNumeric(prhs[4]) ||
mxIsComplex(prhs[4]) ||
mxIsSparse(prhs[4]) ||
!mxIsUint8(prhs[4]) ||
!mxIsLogical(prhs[4]))
mexErrMsgTxt("Input M must be a real matrix of type uint8 (logical)!");
if (mxGetM(prhs[4])!=image_row || mxGetN(prhs[4])!=image_col)
mexErrMsgTxt("Input M must be same size as H!");
mask_image=(unsigned char*)mxGetPr(prhs[4]);
}
else mask_image=(unsigned char*)mxCalloc(image_row*image_col, sizeof(unsigned char));
output_dims[0]=image_row; output_dims[1]=image_col;
plhs[0]=mxCreateNumericArray(2, output_dims, mxUINT8_CLASS, mxREAL);
mxSetLogical(plhs[0]);
output_image=(unsigned char*)mxGetPr(plhs[0]);
bippcca(output_image, input_image, mask_image);
if (gray_level < 1.0 && gray_level > 0.5){
for (m=0; m<image_row*image_col; m++){
output_image[m]=!output_image[m];
}
}
return;
}
More information about the Gcc-bugs
mailing list