oT* rgbConvert(iT* I, int n, int d, int flag, oT nrm) { oT* J = (oT*)wrMalloc(n * (flag == 0 ? (d == 1 ? 1 : d / 3) : d) * sizeof(oT)); int i, n1 = d * (n < 1000 ? n / 10 : 100); oT thr = oT(1.001); if (flag > 1 && nrm == 1) for (i = 0; i < n1; i++) if (I[i] > thr) wrError("For floats all values in I must be smaller than 1."); bool useSse = n % 4 == 0 && typeid(oT) == typeid(float); if (flag == 2 && useSse) for (i = 0; i < d / 3; i++) rgb2luv_sse(I + i * n * 3, (float*)(J + i * n * 3), n, (float)nrm); else if ((flag == 0 && d == 1) || flag == 1) normalize(I, J, n * d, nrm); else if (flag == 0) for (i = 0; i < d / 3; i++) rgb2gray(I + i * n * 3, J + i * n * 1, n, nrm); else if (flag == 2) for (i = 0; i < d / 3; i++) rgb2luv(I + i * n * 3, J + i * n * 3, n, nrm); else if (flag == 3) for (i = 0; i < d / 3; i++) rgb2hsv(I + i * n * 3, J + i * n * 3, n, nrm); else wrError("Unknown flag."); return J; }
long sobel_sharpness(cv::Mat color){ long integral=0; cv::Mat gray=rgb2gray(color); cv::Mat sobel=gray.clone(); int max_abs=0; for(int i=1;i<gray.rows-1;i++){ for(int j=1;j<gray.cols-1;j++){ int gx=(int)(gray.at<uchar>(i+1,j+1)+2*gray.at<uchar>(i,j+1)+gray.at<uchar>(i-1,j+1) - gray.at<uchar>(i-1,j-1)-2*gray.at<uchar>(i,j-1)-gray.at<uchar>(i+1,j-1)); int gy=(int)(gray.at<uchar>(i+1,j+1)+2*gray.at<uchar>(i+1,j)+gray.at<uchar>(i+1,j-1) - gray.at<uchar>(i-1,j-1)-2*gray.at<uchar>(i-1,j)-gray.at<uchar>(i-1,j+1)); integral+=(long)(absol(gx)+absol(gy))/2; //int abs=sqrt(gx*gx+gy*gy); int abs=(int)(absol(gx)+absol(gy))/2; if(abs>max_abs)max_abs=abs; sobel.at<uchar>(i,j)=abs; } } for(int i=1;i<sobel.rows-1;i++){ for(int j=1;j<sobel.cols-1;j++){ sobel.at<uchar>(i,j)=sobel.at<uchar>(i,j)*255/max_abs; } } cv::imshow("sobel",sobel); cv::waitKey(0); return integral; }
std::vector<cv::KeyPoint> grid_fast(const cv::Mat &image, const int max_corners, const int grid_rows, const int grid_cols, const double threshold, const bool nonmax_suppression) { // Prepare input image - make sure it is grayscale cv::Mat image_gray = rgb2gray(image); // Calculate number of grid cells and max corners per cell const int image_width = image.cols; const int image_height = image.rows; const int dx = image_width / grid_cols; const int dy = image_height / grid_rows; const int nb_cells = grid_rows * grid_cols; const size_t max_corners_per_cell = (float) max_corners / (float) nb_cells; // Detect corners in each grid cell std::vector<cv::KeyPoint> keypoints_all; for (int x = 0; x < image_width; x += dx) { for (int y = 0; y < image_height; y += dy) { // Make sure roi width and height are not out of bounds const double w = (x + dx > image_width) ? image_width - x : dx; const double h = (y + dy > image_height) ? image_height - y : dy; // Detect corners in grid cell cv::Rect roi = cv::Rect(x, y, w, h); std::vector<cv::KeyPoint> keypoints; cv::FAST(image_gray(roi), keypoints, threshold, nonmax_suppression); // Sort by keypoint response keypoints = sort_keypoints(keypoints); // Adjust keypoint's position according to the offset limit to max // corners per cell std::vector<cv::KeyPoint> keypoints_adjusted; for (auto &kp : keypoints) { keypoints_adjusted.emplace_back(kp.pt.x += x, kp.pt.y += y, kp.size); if (keypoints_adjusted.size() == max_corners_per_cell) { break; } } // Add to total keypoints detected keypoints_all.insert(std::end(keypoints_all), std::begin(keypoints_adjusted), std::end(keypoints_adjusted)); } } return keypoints_all; }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); connect(ui->actionOpen, SIGNAL(triggered()), this, SLOT(open())); connect(ui->actionReset, SIGNAL(triggered()), this, SLOT(reset())); connect(ui->btn_Left, SIGNAL(clicked()), this, SLOT(turnLeft())); connect(ui->btn_Right, SIGNAL(clicked()), this, SLOT(turnRight())); connect(ui->actionRgb2gray, SIGNAL(triggered()), this, SLOT(rgb2gray())); connect(ui->actionRgb2bw, SIGNAL(triggered()), this, SLOT(rgb2bw())); connect(ui->actionNegative, SIGNAL(triggered()), this, SLOT(negative())); connect(ui->actionStretch, SIGNAL(triggered()), this, SLOT(stretch())); connect(ui->actionLog, SIGNAL(triggered()), this, SLOT(log())); connect(ui->actionHistogramEqualize, SIGNAL(triggered()), this, SLOT(histogramEqualize())); connect(ui->actionHistogramExactSpecifiedEqualize, SIGNAL(triggered()), this, SLOT(histogramExactSpecifiedEqualize())); connect(ui->actionSpatialFilter, SIGNAL(triggered()), this, SLOT(spatialFilter())); connect(ui->actionMedianFilter, SIGNAL(triggered()), this, SLOT(medianFilter())); connect(ui->actionFFT, SIGNAL(triggered()), this, SLOT(makeFFT())); connect(ui->actionOilPaint, SIGNAL(triggered()), this, SLOT(oilPaint())); connect(ui->actionRelief, SIGNAL(triggered()), this, SLOT(relief())); connect(ui->actionEdgeExtraction, SIGNAL(triggered()), this, SLOT(edgeExtraction())); connect(ui->actionGaussianBlur, SIGNAL(triggered()), this, SLOT(gaussianBlur())); connect(ui->actionOpenOperate, SIGNAL(triggered()), this, SLOT(openOp())); connect(ui->actionCloseOperate, SIGNAL(triggered()), this, SLOT(closeOp())); connect(ui->actionExpansion, SIGNAL(triggered()), this, SLOT(expansionOp())); connect(ui->actionCorrosion, SIGNAL(triggered()), this, SLOT(corrosionOp())); connect(ui->checkBox, SIGNAL(toggled(bool)), this, SLOT(saveCheck(bool))); connect(ui->actionSave, SIGNAL(triggered()), this, SLOT(save())); this->ui->graphicsView->setScene(Q_NULLPTR); this->pixmapItem = Q_NULLPTR; this->directory = new QDir(); this->imageProcessor = Q_NULLPTR; this->ui->actionReset->setEnabled(false); this->ui->btn_Left->setEnabled(false); this->ui->btn_Right->setEnabled(false); this->ui->actionRgb2gray->setEnabled(false); this->ui->actionRgb2bw->setEnabled(false); this->ui->actionNegative->setEnabled(false); this->ui->actionStretch->setEnabled(false); this->ui->actionLog->setEnabled(false); this->ui->actionHistogramEqualize->setEnabled(false); this->ui->actionHistogramExactSpecifiedEqualize->setEnabled(false); this->ui->actionSpatialFilter->setEnabled(false); this->ui->actionMedianFilter->setEnabled(false); this->ui->actionFFT->setEnabled(false); this->ui->actionOilPaint->setEnabled(false); this->ui->actionRelief->setEnabled(false); this->ui->actionEdgeExtraction->setEnabled(false); this->ui->actionGaussianBlur->setEnabled(false); this->ui->actionSave->setEnabled(false); }
void testRgb2gray() { image_rgb* rgb = load_image("tests/test.jpg", 1); image_gray *gray = rgb2gray(rgb); CU_ASSERT_EQUAL(gray->data[0], 3); CU_ASSERT_EQUAL(gray->data[1], 5); CU_ASSERT_EQUAL(gray->data[2], 7); CU_ASSERT_EQUAL(gray->data[3], 3); CU_ASSERT_EQUAL(gray->data[4], 5); CU_ASSERT_EQUAL(gray->data[5], 7); CU_ASSERT_EQUAL(gray->data[6], 3); CU_ASSERT_EQUAL(gray->data[7], 5); CU_ASSERT_EQUAL(gray->data[8], 7); image_rgb_delete(rgb); image_gray_delete(gray); }
//change rgb to gray int BMP_rgb2gray(BMPImage *bitmap){ if(Is_24_bitmap(bitmap)!=0){ printf("It's not a 24 bitmap"); BMP_Delete(bitmap); return 1; } int col,row,i,j; unsigned char * tmp = bitmap->data; unsigned char *r,*g,*b; /* DEBUG: print the 1st,2nd,3rd bit */ //int flag_debug = 0; /*debug end*/ rgb_color rgb; gray_color gray; col = bitmap->image_header->Height; row = bitmap->image_header->Width; int width_stride = (4-row*3%4)%4; for(i=0;i < col;i++){ for(j=0;j < row;++j){ r = tmp++; g = tmp++; b = tmp++; /*DEBUG begin: print the 1st,2nd,3rd bit */ //if(flag_debug < 3){ // printf("flag=%d r=%d g=%d b=%d\n",++flag_debug,*r,*g,*b); //} /*DEBUG END*/ rgb.r = *r; rgb.g = *g; rgb.b = *b; gray = rgb2gray(rgb); *r = gray.gray; *g = gray.gray; *b = gray.gray; } tmp+=width_stride; } return 0; }
int main(int argc, char** argv) { int i, j, count; //char** filenames; char id[50] = {0}; char filename[50]; //char seg_file_name[50] = {'s', 'e', 'g', '/', 's', 'e', 'g', '\0'}; //char suffix[5] = {'.', 't', 'x', 't', '\0'}; //FILE* fpout; if (argc != 2) { printf("Please input the path to the pictures.\n");// & the output file name!\n"); exit(1); } // define those features fbrightness brightness; fsaturation saturation; float colorfulness; float naturalness; float contrast; float sharpness; fgray_simplicity gray_simplicity; frgb_simplicity rgb_simplicity; fhsv_simplicity hsv_simplicity; fhue_hist hue_hist; fcolor_harmony color_harmony; fcolor_coherence color_coherence; fsegment_lightness segment_lightness; fSegment_size segment_size; fSegment_hues segment_hues; fcolor_harmony segment_color_harmony; fsaliency_map saliency_map; int n_sift; int n_faces; // point to images IplImage* opencv_img; image_rgb* rgb; image_hsl* hsl; image_hsv* hsv; image_gray* gray; //filenames = get_files_list(argv[1], &count); //fpout = fopen(argv[2], "w"); CvHaarClassifierCascade* classifier = (CvHaarClassifierCascade*)cvLoad("haarcascade_frontalface_alt_tree.xml", 0, 0, 0); strcpy(filename, argv[1]); opencv_img = cvLoadImage(/*filenames[i]*/filename, 1); rgb = load_cv_image(opencv_img); hsl = rgb2hsl(rgb); hsv = rgb2hsv(rgb); gray = rgb2gray(rgb); // tune the filename int loc_beg = -1, loc_end = 0; for (i = 0; i < strlen(filename); ++i) { if (filename[i] == '/') loc_beg = i; if (filename[i] == '.') loc_end = i; } strncpy(id, filename+loc_beg+1, loc_end-loc_beg-1); id[loc_end-loc_beg] = '\0'; /* strncpy(seg_file_name+7, id, strlen(id)); strcpy(seg_file_name+7+strlen(id), suffix); //printf("%s\n", seg_file_name); */ // compute those features brightness = get_brightness_feature(hsl); saturation = get_saturation_feature(hsl); colorfulness = get_colorfulness_feature(rgb); naturalness = get_naturalness_feature(hsl); contrast = get_contrast_feature(hsl); sharpness = get_sharpness_feature(hsl); gray_simplicity = get_grayscale_simplicity_feature(gray); rgb_simplicity = get_rgb_simplicity_feature(rgb); hsv_simplicity = get_hsv_simplicity_feature(hsv); hue_hist = get_hue_histogram_feature(hsv); color_harmony = get_color_harmony_feature(hsl); color_coherence = get_color_coherence_feature(hsv); // KGL //ncut_seg seg_arg = ncut_main_seg_from_file(seg_file_name, rgb->height, rgb->width); int height = rgb->height, width = rgb->width; double double_gray[height * width]; for (i = 0; i < height; ++i) { for (j = 0; j < width; ++j) { // 矩阵存储是按列存储的 double_gray[j*height+i] = 0.299*rgb->r[i*width+j] + 0.587*rgb->g[i*width+j] + 0.114*rgb->b[i*width+j]; } } Map<MatrixXd> imageX(double_gray, height, width); SparseMatrix<double> W = ICgraph(imageX); int* asgn = ncutW(W, 5); int seglable[height * width]; for (j = 0; j < width; ++j) { for (i = 0; i < height; ++i) { seglable[i*width+j] = asgn[j*height+i]; } } free(asgn); ncut_seg seg_arg = ncut_main_seg_from_memory(seglable, height, width); segment_size = get_segsize_feature(seg_arg.seglable, seg_arg.nr, seg_arg.nc, seg_arg.lablenum); segment_hues = get_seghues_feature(seg_arg.seglable, hsv, seg_arg.nr, seg_arg.nc, seg_arg.lablenum); segment_color_harmony = get_segcolor_harmony_feature(hsl, seg_arg.seglable, seg_arg.lablenum); segment_lightness = get_seglightness_feature(hsl, seg_arg.seglable, seg_arg.lablenum); //free(seg_arg.seglable); // - KGL float* saliency = get_saliency_map(rgb); saliency_map = get_saliency_map_feature(saliency, rgb->width, rgb->height); n_sift = get_sift_number(opencv_img); n_faces = get_face_feature(opencv_img, classifier, cvSize(10, 20)); // free those space cvReleaseImage(&opencv_img); image_rgb_delete(rgb); image_hsl_delete(hsl); image_hsv_delete(hsv); image_gray_delete(gray); free(saliency); // output printf("%s,", id); // the filename of the image without suffix printf("%f,%f,%f,%f,", brightness.mean, brightness.stdev, brightness.max, brightness.min); // brightness printf("%f,%f,%f,%f,", saturation.mean, saturation.stdev, saturation.max, saturation.min); // saturation printf("%f,%f,%f,%f,", colorfulness, naturalness, contrast, sharpness); printf("%d,%d,%f,", gray_simplicity.contrast, gray_simplicity.sig_pixels_num, gray_simplicity.stdev); // gray simplicity printf("%d,%f,", rgb_simplicity.sig_pixels_num, rgb_simplicity.ratio); // RGB simplicity printf("%d,%f,", hsv_simplicity.sig_pixels_num, hsv_simplicity.ratio); // HSV simplicity printf("%d,%f,%f,", hue_hist.sig_pixels_num, hue_hist.contrast, hue_hist.stdev); // Hue histogram printf("%f,%f,%f,", color_harmony.bestfit, color_harmony.first_two_dev, color_harmony.avg_dev); // color harmony printf("%d,%f,%f,%d,%d,", color_coherence.n_ccc, color_coherence.r_lc, color_coherence.r_slc, color_coherence.rank, color_coherence.s_rank); // color coherence // KGL printf("%f,%f,", segment_size.rmaxsize, segment_size.rcontrast); // Segment size printf("%d,%d,%d,%d,%f,%f,", segment_hues.fhues1, segment_hues.fhues2, segment_hues.fhues3, segment_hues.fhues4, segment_hues.fhues5, segment_hues.fhues6); // Segment hues printf("%f,%f,%f,", segment_color_harmony.bestfit, segment_color_harmony.first_two_dev, segment_color_harmony.avg_dev); // Segment color harmony printf("%f,%f,%f,", segment_lightness.mseg_ave, segment_lightness.seg_ave_std, segment_lightness.seg_ave_contrast); // Segment lightness // - KGL printf("%f,%d,%f,%f,%d,%f,%f,%f,%f,", saliency_map.r_bg, saliency_map.n_cc, saliency_map.r_lc, saliency_map.asv_lc, saliency_map.n_cc_bg, saliency_map.r_lc_bg, saliency_map.d_cc, saliency_map.d_rtp, saliency_map.d_ci); printf("%d,", n_sift); printf("%d", n_faces); //fclose(fpout); cvReleaseHaarClassifierCascade( &classifier ); //free(filenames); //printf(" - progress: 100.00%%\n"); return (EXIT_SUCCESS); }
virtual void filterSpan(const SkPMColor src[], int count, SkPMColor result[]) { for (int i = 0; i < count; i++) result[i] = rgb2gray(src[i]); }
void CPyramid::create_pyramid(int w, int h, unsigned char* image0, unsigned char* image1, unsigned char* mask0, unsigned char* mask1, int start_res) { std::cout << "Building pyramids \n"; // use cardinal bspline3 prefilter for downsampling kernel::base *pre = new kernel::generalized( new kernel::discrete::delta, new kernel::discrete::sampled(new kernel::generating::bspline3), new kernel::generating::bspline3); // no additional discrete processing kernel::discrete::base *delta = new kernel::discrete::delta; // use mirror extension extension::base *ext = new extension::mirror; image::rgba<float> rgba0; image::load(w,h,image0, &rgba0); image::rgba<float> rgba1; image::load(w,h,image1, &rgba1); image::rgba<float> rgbam0; image::load(w, h, mask0, &rgbam0); image::rgba<float> rgbam1; image::load(w, h, mask1, &rgbam1); CPyramidLevel level; level.image0 = rgb2gray(w,h,image0); level.image1 = rgb2gray(w,h,image1); level.mask0 = rgb2gray(w,h,mask0); level.mask1 = rgb2gray(w,h,mask1); level.blocks_row = ((w + 4) / 5 + 3) / 4 * 4; level.blocks_row += 1 - (level.blocks_row % 2);//make it odd level.blocks_col = (h + 4) / 5; level.blocks_num = level.blocks_row*level.blocks_col; level.w = w; level.h = h; level.inverse_wh = 1.0f / (level.w*level.h); levels.push_back(level); int n = int(log((float)std::min(w,h)) / log(2.0f) - log((float)start_res) / log(2.0f) + 1); for (int el = 1; el< n ; el++) { w = int(floor(w / 2.0f)); h = int(floor(h / 2.0f)); unsigned char* temp_image0 = new unsigned char[w*h * 3]; unsigned char* temp_image1 = new unsigned char[w*h * 3]; unsigned char* temp_mask0 = new unsigned char[w*h * 3]; unsigned char* temp_mask1 = new unsigned char[w*h * 3]; scale(h, w, pre, delta, delta, ext, &rgba0, temp_image0); scale(h, w, pre, delta, delta, ext, &rgba1, temp_image1); scale(h, w, pre, delta, delta, ext, &rgbam0, temp_mask0); scale(h, w, pre, delta, delta, ext, &rgbam1, temp_mask1); CPyramidLevel level; level.image0 = rgb2gray(w,h,temp_image0); level.image1 = rgb2gray(w,h,temp_image1); level.mask0 = rgb2gray(w,h,temp_mask0); level.mask1 = rgb2gray(w,h,temp_mask1); level.blocks_row = ((w + 4) / 5 + 3) / 4 * 4; level.blocks_row += 1 - (level.blocks_row % 2);//make it odd level.blocks_col = (h + 4) / 5; level.blocks_num = level.blocks_row*level.blocks_col; level.w = w; level.h = h; level.inverse_wh = 1.0f / (level.w*level.h); levels.push_back(level); delete[] temp_image0; delete[] temp_image1; delete[] temp_mask0; delete[] temp_mask1; } std::cout << "Finished building pramids \n"; delete pre; delete delta; delete ext; }
/*-------------------------------------------------------------------------------------------------------------- */ void mexFunction( int nlhs, mxArray *plhs[] , int nrhs, const mxArray *prhs[] ) { unsigned char *im; double *H; const int *dimim; double *I; int ny , nx , nynx , dimcolor = 1 , nH = 1 , i; double norma_default[2] = {1 , 1}; double kernelx_default[3] = {-0.5 , 0 , 0.5}; double kernely_default[3] = {-0.5 , 0 , 0.5}; struct opts options; mxArray *mxtemp; double *tmp , temp; int tempint; options.nspyr = 1; options.nori = 9; options.bndori = 0; options.norm = 1; options.kyx = 1; options.kxx = 3; options.kyy = 3; options.kxy = 1; options.color = 0; options.interpolate = 1; options.clamp = 0.2; /* Input 1 */ if( (mxGetNumberOfDimensions(prhs[0]) > 3) || !mxIsUint8(prhs[0]) ) { mexErrMsgTxt("I must be (ny x nx x [3]) in UINT8 format\n"); } im = (unsigned char *)mxGetData(prhs[0]); dimim = mxGetDimensions(prhs[0]); ny = dimim[0]; nx = dimim[1]; nynx = ny*nx; /* Input 2 */ if ((nrhs > 1) && !mxIsEmpty(prhs[1]) ) { mxtemp = mxGetField(prhs[1] , 0 , "spyr"); if(mxtemp != NULL) { if( mxGetN(mxtemp) != 4 ) { mexErrMsgTxt("spyr must be (nscale x 4) in double format"); } options.spyr = mxGetPr(mxtemp); options.nspyr = mxGetM(mxtemp); } else { options.nspyr = 1; options.spyr = (double *)mxMalloc(4*sizeof(double)); options.spyr[0] = 1.0; options.spyr[1] = 1.0; options.spyr[2] = 1.0; options.spyr[3] = 1.0; } mxtemp = mxGetField( prhs[1], 0, "norma" ); if(mxtemp != NULL) { if((mxGetM(mxtemp) != 1) && (mxGetN(mxtemp) != 2) ) { mexErrMsgTxt("options.norma must be (1 x 2) in double format"); } options.norma = mxGetPr(mxtemp); } else { options.norma = (double *)mxMalloc(2*sizeof(double)); for(i = 0 ; i < 2 ; i++) { options.norma[i] = norma_default[i]; } } mxtemp = mxGetField( prhs[1], 0, "kernelx" ); if(mxtemp != NULL) { options.kernelx = mxGetPr(mxtemp); options.kyx = (int) mxGetM(mxtemp); options.kxx = (int) mxGetN(mxtemp); } else { options.kernelx = (double *)mxMalloc(3*sizeof(double)); for(i = 0 ; i < 3 ; i++) { options.kernelx[i] = kernelx_default[i]; } } mxtemp = mxGetField( prhs[1], 0, "kernely" ); if(mxtemp != NULL) { options.kernely = mxGetPr(mxtemp); options.kyy = (int) mxGetM(mxtemp); options.kxy = (int) mxGetN(mxtemp); } else { options.kernely = (double *)mxMalloc(3*sizeof(double)); for(i = 0 ; i < 3 ; i++) { options.kernely[i] = kernely_default[i]; } } mxtemp = mxGetField(prhs[1] , 0 , "color"); if(mxtemp != NULL) { tmp = mxGetPr(mxtemp); tempint = (int) tmp[0]; if( (tempint < 0) || (tempint > 6)) { mexPrintf("color = {0,1,2,3,4,5}, force to 0\n"); options.color = 0; } else { options.color = tempint; } } mxtemp = mxGetField(prhs[1] , 0 , "nori"); if(mxtemp != NULL) { tmp = mxGetPr(mxtemp); tempint = (int) tmp[0]; if( (tempint < 1)) { mexPrintf("nori > 0, force to 9"); options.nori = 9; } else { options.nori = tempint; } } mxtemp = mxGetField(prhs[1] , 0 , "norm"); if(mxtemp != NULL) { tmp = mxGetPr(mxtemp); tempint = (int) tmp[0]; if( (tempint < 0) || (tempint > 4) ) { mexPrintf("norm = {0 , 1 , 2 , 3 , 4}, force to 1"); options.norm = 1; } else { options.norm = tempint; } } mxtemp = mxGetField(prhs[1] , 0 , "bndori"); if(mxtemp != NULL) { tmp = mxGetPr(mxtemp); tempint = (int) tmp[0]; if( (tempint < 0) || (tempint > 1) ) { mexErrMsgTxt("bndori = {0 , 1}, force to 1"); options.bndori = 0; } else { options.bndori = tempint; } } mxtemp = mxGetField(prhs[1] , 0 , "interpolate"); if(mxtemp != NULL) { tmp = mxGetPr(mxtemp); tempint = (int) tmp[0]; if( (tempint < 0) || (tempint > 1)) { mexPrintf("interpolate = {0,1}, force to 1"); options.interpolate = 1; } else { options.interpolate = tempint; } } mxtemp = mxGetField(prhs[1] , 0 , "clamp"); if(mxtemp != NULL) { tmp = mxGetPr(mxtemp); temp = tmp[0]; if( (temp < 0.0) ) { mexPrintf("clamp must be >= 0, force to 0.2"); options.clamp = 0.2; } else { options.clamp = temp; } } } else { options.nspyr = 1; options.spyr = (double *)mxMalloc(4*sizeof(double)); options.spyr[0] = 1.0; options.spyr[1] = 1.0; options.spyr[2] = 1.0; options.spyr[3] = 1.0; options.norma = (double *)mxMalloc(2*sizeof(double)); for(i = 0 ; i < 2 ; i++) { options.norma[i] = norma_default[i]; } options.kernelx = (double *)mxMalloc(3*sizeof(double)); options.kernely = (double *)mxMalloc(3*sizeof(double)); for(i = 0 ; i < 3 ; i++) { options.kernelx[i] = kernelx_default[i]; options.kernely[i] = kernely_default[i]; } } if((mxGetNumberOfDimensions(prhs[0]) == 2)) { options.color = 0; I = (double *)mxMalloc(nynx*sizeof(double)); dimcolor = 1; for (i = 0 ; i < nynx ; i++) { I[i] = (double)im[i]; } } else { if((options.color == 0) ) { I = (double *)mxMalloc(nynx*sizeof(double)); rgb2gray(im , ny , nx , I); dimcolor = 1; } else if (options.color == 1) { I = (double *)mxMalloc(3*nynx*sizeof(double)); for (i = 0 ; i < 3*nynx ; i++) { I[i] = (double)im[i]; } dimcolor = 3; } else if (options.color == 2) { I = (double *)mxMalloc(3*nynx*sizeof(double)); rgb2nrgb(im , ny , nx , I); dimcolor = 3; } else if (options.color == 3) { I = (double *)mxMalloc(3*nynx*sizeof(double)); rgb2opponent(im , ny , nx , I); dimcolor = 3; } else if(options.color == 4) { I = (double *)mxMalloc(2*nynx*sizeof(double)); rgb2nopponent(im , ny , nx , I); dimcolor = 2; } else if(options.color == 5) { I = (double *)mxMalloc(nynx*sizeof(double)); rgb2hue(im , ny , nx , I); dimcolor = 1; } } /*----------------------- Outputs -------------------------------*/ nH = number_subwindows(options.spyr , options.nspyr ); plhs[0] = mxCreateDoubleMatrix(dimcolor*nH*options.nori , 1 , mxREAL); H = mxGetPr(plhs[0]); /*------------------------ Main Call ----------------------------*/ mlhoee_spyr(I , H , ny , nx , nH , dimcolor , options ); /*--------------------------- Free memory -----------------------*/ if ( (nrhs > 1) && !mxIsEmpty(prhs[1]) ) { if ( (mxGetField( prhs[1] , 0 , "spyr" )) == NULL ) { mxFree(options.spyr); } if ( (mxGetField( prhs[1] , 0 , "norma" )) == NULL ) { mxFree(options.norma); } if ( (mxGetField( prhs[1] , 0 , "kernelx" )) == NULL ) { mxFree(options.kernelx); } if ( (mxGetField( prhs[1] , 0 , "kernely" )) == NULL ) { mxFree(options.kernely); } } else { mxFree(options.spyr); mxFree(options.norma); mxFree(options.kernelx); mxFree(options.kernely); } mxFree(I); }