void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) { OID ID; /* OMEIS data structures */ omeis* is; pixHeader* head; /* MATLAB data structueres */ mxArray *m_url, *m_sessionkey; mxArray *permute_inputs[2]; mxArray *copy_input_array; /* we need a local copy so we can transpose it */ char* url, *sessionkey; if (nrhs != 3) mexErrMsgTxt("\n [pix] = setPixels (is, ID, pixels)"); if (!mxIsStruct(prhs[0])) mexErrMsgTxt("setPixels requires the first input to be the struct outputed" " from openConnectionOMEIS\n"); if (!(m_url = mxGetField(prhs[0], 0, "url"))) mexErrMsgTxt("setPixels requires the first input, OMEIS struct, to have field: url"); if (!(m_sessionkey = mxGetField(prhs[0], 0, "sessionkey"))) mexErrMsgTxt("setPixels requires the first input, OMEIS struct, to have field: sessionkey"); if (!mxIsChar(m_url) || !mxIsChar(m_sessionkey)) mexErrMsgTxt("OMEIS field aren't character array.\n"); if (!mxIsNumeric(prhs[1])) mexErrMsgTxt("setPixels requires the second input to be the PixelsID\n") ; ID = (OID) mxGetScalar(prhs[1]) ; url = mxArrayToString(m_url); sessionkey = mxArrayToString(m_sessionkey); is = openConnectionOMEIS (url, sessionkey); if (!(head = pixelsInfo (is, ID))){ char err_str[128]; sprintf(err_str, "PixelsID %llu or OMEIS URL '%s' is probably wrong\n", ID, is->url); /* clean up */ mxFree(url); mxFree(sessionkey); mxFree(is); mexErrMsgTxt(err_str); } /* In OMEIS Size_X corresponds to columns and Size_Y corresponds to rows. This is diametrically opposite to MATLAB's assumptions. hence we do "$matlab_var_name = permute($matlab_var_name, [2 1 3 4 5]);" the hard way (groan) */ permute_inputs[0] = prhs[2]; /* permute_input isn't being modified so discarding the const qualifier is okay */ permute_inputs[1] = mxCreateDoubleMatrix(1, 5, mxREAL); mxGetPr(permute_inputs[1])[0] = 2; mxGetPr(permute_inputs[1])[1] = 1; mxGetPr(permute_inputs[1])[2] = 3; mxGetPr(permute_inputs[1])[3] = 4; mxGetPr(permute_inputs[1])[4] = 5; /* mexCallMATLAB allocates memory for copy_input_array */ if (mexCallMATLAB(1, ©_input_array, 2, permute_inputs, "permute")) { /* clean up */ mxFree(url); mxFree(sessionkey); mxFree(head); mxFree(is); char err_str[128]; sprintf(err_str, "Couldn't permute the pixels to get them in MATLAB orientation"); mexErrMsgTxt(err_str); } /* check dimension and class check */ const mwSize* dims = mxGetDimensions (copy_input_array); switch (mxGetNumberOfDimensions (copy_input_array)) { char err_str[128]; case 5: if (head->dt != dims[4]) { sprintf (err_str, "5th Dimension (%d) of input array doesn't match OMEIS Pixels (%d).\n", dims[4], head->dt); mexErrMsgTxt(err_str); } case 4: if (head->dc != dims[3]) { sprintf (err_str, "4th Dimension (%d) of input array doesn't match OMEIS Pixels (%d).\n", dims[3], head->dc); mexErrMsgTxt(err_str); } case 3: if (head->dz != dims[2]){ sprintf (err_str, "3th Dimension (%d) of input array doesn't match OMEIS Pixels (%d).\n", dims[2], head->dz); mexErrMsgTxt(err_str); } case 2: if (head->dy != dims[1]){ sprintf (err_str, "Height (%d) of input array doesn't match OMEIS Pixels (%d).\n", dims[1], head->dy); mexErrMsgTxt(err_str); } case 1: if (head->dx != dims[0]){ sprintf (err_str, "Width (%d) of input array doesn't match OMEIS Pixels (%d).\n", dims[0], head->dx); mexErrMsgTxt(err_str); } break; default: /* clean up */ mxFree(url); mxFree(sessionkey); mxFree(head); mxFree(is); mxDestroyArray(copy_input_array); mexErrMsgTxt("Input Array must be 5D or less"); break; } pixHeader tmp_head; CtoOMEISDatatype ((char*) mxGetClassName(copy_input_array), &tmp_head); if ( !samePixelType(&tmp_head, head)) { /* clean up */ mxFree(url); mxFree(sessionkey); mxFree(head); mxFree(is); mxDestroyArray(copy_input_array); mexErrMsgTxt("Types of input array and Pixels don't match\n"); } /* set the pixels */ int pix = setPixels (is, ID, mxGetPr(copy_input_array)); /* record number of pixels written */ plhs[0] = mxCreateScalarDouble((double) pix); /* clean up */ mxFree(url); mxFree(sessionkey); mxFree(head); mxFree(is); mxDestroyArray(copy_input_array); }
void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) { OID ID; /* OMEIS data structures */ omeis* is; pixHeader* head = (pixHeader*) mxMalloc(sizeof(pixHeader)); /* MATLAB data structueres */ mxArray *m_dx, *m_dy, *m_dz, *m_dc, *m_dt, *m_bp, *m_isSigned, *m_isFloat; mxArray *m_url, *m_sessionkey; char* url, *sessionkey; if (nrhs != 2) mexErrMsgTxt("\n [ID] = newPixels (is, ph)"); if (!mxIsStruct(prhs[0])) mexErrMsgTxt("newPixels requires the first input to be the struct outputed" " from openConnectionOMEIS\n"); if (!(m_url = mxGetField(prhs[0], 0, "url"))) mexErrMsgTxt("newPixels requires the first input, OMEIS struct, to have field: url"); if (!(m_sessionkey = mxGetField(prhs[0], 0, "sessionkey"))) mexErrMsgTxt("newPixels requires the first input, OMEIS struct, to have field: sessionkey"); if (!mxIsChar(m_url) || !mxIsChar(m_sessionkey)) mexErrMsgTxt("OMEIS field aren't character array.\n"); if (!mxIsStruct(prhs[0])) mexErrMsgTxt("newPixels requires the first input to be the struct outputed" " from openConnectionOMEIS\n"); if (!mxIsStruct(prhs[1])) mexErrMsgTxt("newPixels requires the second input to be a pixHeader struct."); if (!(m_dx = mxGetField(prhs[1], 0, "dx"))) mexErrMsgTxt("newPixels requires the second input, pixHeader struct, to have field: dx"); if (!(m_dy = mxGetField(prhs[1], 0, "dy"))) mexErrMsgTxt("newPixels requires the second input, pixHeader struct, to have field: dy"); if (!(m_dz = mxGetField(prhs[1], 0, "dz"))) mexErrMsgTxt("newPixels requires the second input, pixHeader struct, to have field: dz"); if (!(m_dc = mxGetField(prhs[1], 0, "dc"))) mexErrMsgTxt("newPixels requires the second input, pixHeader struct, to have field: dc"); if (!(m_dt = mxGetField(prhs[1], 0, "dt"))) mexErrMsgTxt("newPixels requires the second input, pixHeader struct, to have field: dt"); if (!(m_bp = mxGetField(prhs[1], 0, "bp"))) mexErrMsgTxt("newPixels requires the second input, pixHeader struct, to have field: bp"); if (!(m_isSigned = mxGetField(prhs[1], 0, "isSigned"))) mexErrMsgTxt("newPixels requires the second input, pixHeader struct, to have field: isSigned"); if (!(m_isFloat = mxGetField(prhs[1], 0, "isFloat"))) mexErrMsgTxt("newPixels requires the second input, pixHeader struct, to have field: isFloat"); head->dx = (ome_dim) mxGetScalar(m_dx); head->dy = (ome_dim) mxGetScalar(m_dy); head->dz = (ome_dim) mxGetScalar(m_dz); head->dc = (ome_dim) mxGetScalar(m_dc); head->dt = (ome_dim) mxGetScalar(m_dt); head->bp = (u_int8_t) mxGetScalar(m_bp); head->isSigned = (u_int8_t) mxGetScalar(m_isSigned); head->isFloat = (u_int8_t) mxGetScalar(m_isFloat); url = mxArrayToString(m_url); sessionkey = mxArrayToString(m_sessionkey); is = openConnectionOMEIS (url, sessionkey); if ( !(ID = newPixels (is, head)) ) { /* clean up */ mxFree(url); mxFree(sessionkey); mxFree(head); mxFree(is); mexErrMsgTxt("newPixels OMEIS method failed.\n"); } plhs[0] = mxCreateScalarDouble((double) ID); /* clean up */ mxFree(url); mxFree(sessionkey); mxFree(head); mxFree(is); }
void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) { OID ID; /* OMEIS data structures */ omeis* is; pixHeader* head; void* pixels; /* MATLAB data structueres */ mxArray *m_url, *m_sessionkey; mxArray *permute_inputs[2]; int result; char* url, *sessionkey; if (nrhs != 12) mexErrMsgTxt("\n [pixels] = getROI (is, ID, row0 (OME:y0), column0 (OME:x0), z0, c0, t0, row1 (OME:y1), column1 (OME:x1), z1, c1, t1)"); if (!mxIsStruct(prhs[0])) mexErrMsgTxt("getROI requires the first input to be the struct outputed" " from openConnectionOMEIS\n"); if (!(m_url = mxGetField(prhs[0], 0, "url"))) mexErrMsgTxt("getROI requires the first input, OMEIS struct, to have field: url"); if (!(m_sessionkey = mxGetField(prhs[0], 0, "sessionkey"))) mexErrMsgTxt("getROI requires the first input, OMEIS struct, to have field: sessionkey"); if (!mxIsChar(m_url) || !mxIsChar(m_sessionkey)) mexErrMsgTxt("OMEIS field aren't character array.\n"); if (!mxIsNumeric(prhs[1])) mexErrMsgTxt("getROI requires the second input to be the PixelsID\n") ; ID = (OID) mxGetScalar(prhs[1]) ; /* get ROI */ /* NB x0/y0 and x1/y1 are switched on purpose because of the different orientations used in MATLAB and OME. See note below */ int y0 = (int) mxGetScalar(prhs[2]); /* switched */ int x0 = (int) mxGetScalar(prhs[3]); /* switched */ int z0 = (int) mxGetScalar(prhs[4]); int c0 = (int) mxGetScalar(prhs[5]); int t0 = (int) mxGetScalar(prhs[6]); int y1 = (int) mxGetScalar(prhs[7]); /* switched */ int x1 = (int) mxGetScalar(prhs[8]); /* switched */ int z1 = (int) mxGetScalar(prhs[9]); int c1 = (int) mxGetScalar(prhs[10]); int t1 = (int) mxGetScalar(prhs[11]); url = mxArrayToString(m_url); sessionkey = mxArrayToString(m_sessionkey); is = openConnectionOMEIS (url, sessionkey); if (!(head = pixelsInfo (is, ID))) { char err_str[128]; sprintf(err_str, "PixelsID %llu or OMEIS URL '%s' is probably wrong\n", ID, is->url); /* clean up */ mxFree(url); mxFree(sessionkey); mxFree(is); mexErrMsgTxt(err_str); } if (!(pixels = getROI (is, ID, x0, y0, z0, c0, t0, x1, y1, z1, c1, t1))) { /* clean up */ mxFree(url); mxFree(sessionkey); mxFree(head); mxFree(is); char err_str[128]; sprintf(err_str, "Couldn't load ROI from pixelsID %llu. ROI dims are probably wrong.\n", ID); mexErrMsgTxt(err_str); } /* convert ROI to dims */ mwSize dims[5]; dims[0] = (mwSize) (x1-x0+1); dims[1] = (mwSize) (y1-y0+1); dims[2] = (mwSize) (z1-z0+1); dims[3] = (mwSize) (c1-c0+1); dims[4] = (mwSize) (t1-t0+1); /* attach pixels from OMEIS to MATLAB array */ mwSize tmp_dims[2] = {1,1}; plhs[0] = mxCreateNumericArray (2, tmp_dims, OMEIStoMATLABDatatype(head), mxREAL); mxSetData (plhs[0], pixels); mxSetDimensions (plhs[0], dims, 5); /* In OMEIS Size_X corresponds to columns and Size_Y corresponds to rows. This is diametrically opposite to MATLAB's assumptions. hence we do "$matlab_var_name = permute($matlab_var_name, [2 1 3 4 5]);" the hard way (groan) */ permute_inputs[0] = plhs[0]; permute_inputs[1] = mxCreateDoubleMatrix(1, 5, mxREAL); mxGetPr(permute_inputs[1])[0] = 2; mxGetPr(permute_inputs[1])[1] = 1; mxGetPr(permute_inputs[1])[2] = 3; mxGetPr(permute_inputs[1])[3] = 4; mxGetPr(permute_inputs[1])[4] = 5; /* returns 0 if successful */ result = mexCallMATLAB(1, plhs, 2, permute_inputs, "permute"); /* clean up */ mxFree(url); mxFree(sessionkey); mxFree(head); mxFree(is); mxDestroyArray(permute_inputs[1]); if (result) { char err_str[128]; sprintf(err_str, "Couldn't permute the pixels to get them in MATLAB orientation"); mexErrMsgTxt(err_str); } }
void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) { OID ID; /* OMEIS data structures */ omeis* is; pixHeader* head; void* pixels; /* MATLAB data structueres */ mxArray *m_url, *m_sessionkey; mxArray *permute_inputs[2]; int result; char* url, *sessionkey; if (nrhs != 2) mexErrMsgTxt("\n [pixels] = getPixels (is, ID)"); if (!mxIsStruct(prhs[0])) mexErrMsgTxt("getPixels requires the first input to be the struct outputed" " from openConnectionOMEIS\n"); if (!(m_url = mxGetField(prhs[0], 0, "url"))) mexErrMsgTxt("getPixels requires the first input, OMEIS struct, to have field: url"); if (!(m_sessionkey = mxGetField(prhs[0], 0, "sessionkey"))) mexErrMsgTxt("getPixels requires the first input, OMEIS struct, to have field: sessionkey"); if (!mxIsChar(m_url) || !mxIsChar(m_sessionkey)) mexErrMsgTxt("OMEIS field aren't character array.\n"); if (!mxIsNumeric(prhs[1])) mexErrMsgTxt("getPixels requires the second input to be the PixelsID\n") ; ID = (OID) mxGetScalar(prhs[1]) ; url = mxArrayToString(m_url); sessionkey = mxArrayToString(m_sessionkey); is = openConnectionOMEIS (url, sessionkey); if (!(head = pixelsInfo (is, ID))) { char err_str[128]; sprintf(err_str, "PixelsID %llu or OMEIS URL '%s' is probably wrong\n", ID, is->url); /* clean up */ mxFree(url); mxFree(sessionkey); mxFree(is); mexErrMsgTxt(err_str); } /* figure out dimensions */ mwSize dims[5]; dims[0] = (mwSize) head->dx; dims[1] = (mwSize) head->dy; dims[2] = (mwSize) head->dz; dims[3] = (mwSize) head->dc; dims[4] = (mwSize) head->dt; if (!(pixels = getPixels (is, ID))) { /* clean up */ mxFree(url); mxFree(sessionkey); mxFree(head); mxFree(is); char err_str[128]; sprintf(err_str, "Couldn't load pixelsID %llu\n", ID); mexErrMsgTxt(err_str); } /* attach pixels from OMEIS to MATLAB array */ mwSize tmp_dims[2] = {1,1}; plhs[0] = mxCreateNumericArray (2, tmp_dims, OMEIStoMATLABDatatype(head), mxREAL); mxSetData (plhs[0], pixels); mxSetDimensions (plhs[0], dims, 5); /* In OMEIS Size_X corresponds to columns and Size_Y corresponds to rows. This is diametrically opposite to MATLAB's assumptions. hence we do "$matlab_var_name = permute($matlab_var_name, [2 1 3 4 5]);" the hard way (groan) */ permute_inputs[0] = plhs[0]; permute_inputs[1] = mxCreateDoubleMatrix(1, 5, mxREAL); mxGetPr(permute_inputs[1])[0] = 2; mxGetPr(permute_inputs[1])[1] = 1; mxGetPr(permute_inputs[1])[2] = 3; mxGetPr(permute_inputs[1])[3] = 4; mxGetPr(permute_inputs[1])[4] = 5; /* returns 0 if successful */ result = mexCallMATLAB(1, plhs, 2, permute_inputs, "permute"); /* clean up */ mxFree(url); mxFree(sessionkey); mxFree(head); mxFree(is); mxDestroyArray(permute_inputs[1]); /* If the flip failed write a message, we are doing it after cleanup */ if (result) { char err_str[128]; sprintf(err_str, "Couldn't permute the pixels to get them in MATLAB orientation"); mexErrMsgTxt(err_str); } }
int main (int argc, char* argv[]) { OID ID; int distance, angle; u_int8_t** p_gray; /*Image converted for texture calcs*/ TEXTURE* features ; /*Returned struct of features*/ /* OMEIS data structures */ omeis* is; pixHeader* head; void* pixels; if (argc != 4) { fprintf(stderr, "\n mb_texture (im, distance, angle),\n\n" "This function returns the 14 image texture statistics described by R. Haralick.\n" "The statistics are calculated from the image's co-occurence matrix specified\n" "for a particular distance and angle. Distance is measured in pixels and\n" "the angle is measured in degrees.\n"); return EXIT_FAILURE; } sscanf(argv[1], "%llu", &ID); sscanf(argv[2], "%d", &distance); sscanf(argv[3], "%d", &angle); is = openConnectionOMEIS ("http://localhost/cgi-bin/omeis","0000"); if (!(head = pixelsInfo (is, ID))){ fprintf (stderr, "PixelsID %llu or OMEIS URL '%s' is probably wrong\n", ID, is->url); return EXIT_FAILURE; } if (!(pixels = getPixels (is, ID))) { fprintf (stderr, "Couldn't get Pixels with ID %llu\n", ID); return 0; } p_gray = (u_int8_t**) OMEIStoCArray (pixels, head, "unsigned char"); if (! (features=Extract_Texture_Features(distance, angle, p_gray, head->dy, head->dx, 255))) { fprintf(stderr, "ERROR: Could not compute Haralick Features.\n"); return EXIT_FAILURE; } printf("%f\n",features->ASM); printf("%f\n",features->contrast); printf("%f\n",features->correlation); printf("%f\n",features->variance); printf("%f\n",features->IDM); printf("%f\n",features->sum_avg); printf("%f\n",features->sum_var); printf("%f\n",features->sum_entropy); printf("%f\n",features->entropy); printf("%f\n",features->diff_var); printf("%f\n",features->diff_entropy); printf("%f\n",features->meas_corr1); printf("%f\n",features->meas_corr2); printf("%f\n",features->max_corr_coef); free(p_gray); free(pixels); free(features); return(EXIT_SUCCESS); }