source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/Superpixels/SourceCode/segment/segmentImgOpt.cpp @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 3.0 KB
Line 
1/*Including the mexFunction as a matlab interface
2usage:
3a = segmentImgOpt( sigm, k, min, img, OltputFolder, PPMoption);
4 Input--
5 sigm
6 k
7 min
8 img: rgb 3 color channel 2d matrix
9 OltputFolder : path of the  output folder
10 PPMoption : 1 if storaging PPM file
11 
12 Output--
13 a : unsorted index superpixel 2d matrix*/
14
15
16
17#include <stdio.h>
18#include <cstdlib>
19#include <cstring>
20#include "image.h"
21#include "misc.h"
22#include "pnmfile.h"
23#include "segment-image-opt.h"
24#include "mex.h"
25//#include <cstdio>
26
27/* */
28#define PPM_PATH        prhs[4]
29#define PPM_OPTION        prhs[5]
30
31void mexFunction( int nlhs, mxArray *plhs[],
32                  int nrhs, const mxArray *prhs[] )
33{
34  if(nrhs!=6) {
35    mexErrMsgTxt("usage: segmentedImage = SEGMENT(sigma, k, min, inputimage, OltputFolder, PPMoption)");
36  } else if(nlhs>1) {
37    mexErrMsgTxt("Too many output arguments");
38  }
39  if (!mxIsChar( PPM_PATH) || mxIsComplex( PPM_PATH) ) {
40        mexErrMsgTxt("WRL path is not a string.");
41    }
42
43  const int *dims; 
44  int height, width, ndim;
45  char *PpmFolder;
46  float sigma = (float)*mxGetPr(prhs[0]);
47  float k = (float)*mxGetPr(prhs[1]);
48  int min_size = (int)*mxGetPr(prhs[2]);
49  unsigned char *Imptr;
50  double *SegOut;
51  PpmFolder = mxArrayToString(PPM_PATH);
52  double *PpmOption = mxGetPr( PPM_OPTION);
53/*  float *Imptr;*/
54  unsigned short int *output;
55 
56  height=(mxGetDimensions(prhs[3]))[0];
57  width=(mxGetDimensions(prhs[3]))[1];
58
59  Imptr = (unsigned char*) mxGetPr(prhs[3]);
60/*  Imptr = (float*) mxGetPr(prhs[3]);*/
61/*  image<rgb> *im = new image<rgb>(width, height, true);*/
62/*  image<unsigned char> *r = new image<unsigned char>(width, height, true);
63  image<unsigned char> *g = new image<unsigned char>(width, height, true);
64  image<unsigned char> *b = new image<unsigned char>(width, height, true);*/
65
66/*  for (int y = 0; y < height; y++) {
67    for (int x = 0; x < width; x++) {*/
68/*      imRef(r, x, y) = Imptr[height*x+y];
69      imRef(g, x, y) = Imptr[height*x+y];
70      imRef(b, x, y) = Imptr[height*x+y];*/
71/*      imRef(g, x, y) = Imptr[height*x+y + (width* height * 1 -1)];
72      imRef(b, x, y) = Imptr[height*x+y + (width* height * 2 -1)];*/
73/*      imRef(r, x, y) = Imptr[height*x+y];
74      imRef(g, x, y) = Imptr[height*x+y + (width* height * 1 -1)];
75      imRef(b, x, y) = Imptr[height*x+y + (width* height * 2 -1)];*/
76/*      imRef(im, x, y).r = Imptr[height*x+y];
77      imRef(im, x, y).g = Imptr[height*x+y + (width* height * 1 -1)];
78      imRef(im, x, y).b = Imptr[height*x+y + (width* height * 2 -1)];*/
79/*    }
80  }*/
81/*  mexWarnMsgTxt(" r g b setup OK");*/
82/*  memcpy(im->data, mxGetData(prhs[3]), height* width * sizeof(rgb));*/
83  plhs[0] = mxCreateDoubleMatrix ( height, width, mxREAL);
84  SegOut =  mxGetPr(plhs[0]);
85
86/*  image<rgb> *seg = segment_image( im, SegOut, height, width, sigma, k, min_size);*/
87  image<rgb> *seg = segment_image( Imptr, SegOut, height, width, sigma, k, min_size, PpmOption);
88
89  if (*PpmOption){
90      savePPM( seg, PpmFolder);
91  }
92
93  /*delete [] r;
94  delete [] g;
95  delete [] b;*/
96  return;
97}
Note: See TracBrowser for help on using the repository browser.