//函数定义 int H5() { char fname[file_name_len]; struct IMG image; struct IMG * pimg=ℑ struct Template tml;//定义模版 struct Template * ptml=&tml; int * arr=NULL; char ch[1024]; char * pch=ch; //lena------------------------- strcpy(fname,"lena.ppm"); ReadPPM(fname,pimg); arr=(int *)malloc(sizeof(int)*3*3);//申请一个3*3的模版矩阵 //锐化模版 strcpy(ch,"Harpening 锐化模版导入成功"); /* 0 -1 0 * -1 5 -1 * 0 -1 0 * */ //arr[0][0]=0;arr[0][1]=-1;arr[0][2]=0; //arr[1][0]=-1;arr[1][1]=5;arr[1][2]=-1; //arr[2][0]=0;arr[2][1]=-1;arr[2][2]=0; arr[0]=0; arr[1]=-1; arr[2]=0; arr[3]=-1; arr[4]=5; arr[5]=-1; arr[6]=0; arr[7]=-1; arr[8]=0; ptml->square=arr; ptml->name=pch; ptml->x=3; ptml->y=3; ptml->max=1; Convolution(pimg,ptml); strcpy(fname,"锐化后的lena.ppm"); WritePPM(fname,pimg); WritePPM(fname,pimg); //边缘检测 FreePPM(pimg); strcpy(fname,"lena.ppm"); ReadPPM(fname,pimg); strcpy(ch,"Edge Detection边缘检测Sobel算子"); /* -1 0 1 * -2 0 2 * -1 0 1 * */ arr[0]=-1; arr[1]=0; arr[2]=1; arr[3]=-2; arr[4]=0; arr[5]=2; arr[6]=-1; arr[7]=0; arr[8]=1; ptml->square=arr; ptml->name=pch; ptml->x=3;ptml->y=3; ptml->max=4; Convolution(pimg,ptml); strcpy(fname,"边缘检测后的lena.ppm"); WritePPM(fname,pimg); free(arr); //lena-------------------------- return 0; }
void TwoDofControllerPDModel::setup(double _ke, double _kd, double _tc, double _dt, unsigned int _range) { ke = _ke; kd = _kd; tc = _tc; dt = _dt; convolutions.clear(); for (int i = 0; i < NUM_CONVOLUTION_TERM; i++) { convolutions.push_back(Convolution(_dt, _range)); } reset(); }
vector<InterestPoint> InterestPointsDetector::detectHarris(float threshold) { Kernel sobelX = Kernel::createSobelKernelX(); Convolution convX = Convolution(sobelX, type); FImage derXStore = convX.apply(source); Kernel sobelY = Kernel::createSobelKernelY(); Convolution convY = Convolution(sobelY, type); FImage derYStore = convY.apply(source); FImage minLambdasStore = calculateMinLambdasStore(derXStore, derYStore); vector<InterestPoint> points = determinePointsByRadius( threshold, radiusOfNeighborhood, minLambdasStore); vector<InterestPoint> mostPowerPoint = adaptiveNonMaximumSuppression(points); vector<InterestPoint> mostPPWithOrientation = calculateOrientations(mostPowerPoint); return mostPPWithOrientation; }
void TwoDofControllerDynamicsModel::setup(TwoDofControllerDynamicsModel::TwoDofControllerDynamicsModelParam &_param, unsigned int _range) { param.alpha = _param.alpha; param.beta = _param.beta; param.ki = _param.ki; param.tc = _param.tc; param.dt = _param.dt; convolutions.clear(); for (int i = 0; i < NUM_CONVOLUTION_TERM; i++) { convolutions.push_back(Convolution(_param.dt, _range)); } integrate_exp_sinh_current.setup(_param.dt, _range); reset(); }
TwoDofControllerDynamicsModel::TwoDofControllerDynamicsModel() { param = TwoDofControllerDynamicsModel::TwoDofControllerDynamicsModelParam(); // use default constructor current_time = 0; convolutions.clear(); exp_sinh.clear(); for (int i = 0; i < NUM_CONVOLUTION_TERM; i++) { convolutions.push_back(Convolution(0.0, 0.0)); } integrate_exp_sinh_current.setup(0.0, 0.0); }
void image::BoxBlur(int k){ boost::multi_array<float,2> kernel(boost::extents[k][k]); for(int j=0;j<k;j++){for(int i= 0;i<k;i++){ kernel[i][j]= float(1/(float(k)*float(k))); }} boost::multi_array<unsigned char,2> output(boost::extents[this->img.shape()[0]][this->img.shape()[1]]); Convolution(this->img,output,kernel); this->img = output; }
unsigned int image::sharpness(void){ boost::multi_array<float,2> kernel(boost::extents[3][3]); kernel[0][0]=0;kernel[1][0]=1;kernel[2][0]=0; kernel[0][1]=1;kernel[1][1]=-4;kernel[2][1]=1; kernel[0][2]=0;kernel[1][2]=1;kernel[2][2]=0; boost::multi_array<unsigned char,2> output(boost::extents[this->img.shape()[0]][this->img.shape()[1]]); Convolution(this->img,output, kernel); unsigned int max = 0; for(int x=3; x<int(output.shape()[0])-2; ++x) for(int y=3; y<int(output.shape()[1])-2; ++y) max = std::max(static_cast<unsigned int>(output[x][y]), max); unsigned int max_return = max; return max_return; }
void Gaussian ( GtkWidget *widget, gpointer gdata ) { GuiData *gd = GetGuiData (); if ( gd->gauss == NULL ) { int i; gsl_matrix *gauss = NULL; gsl_vector *v = gsl_vector_alloc (2); gsl_vector_set ( v, 0, 5 ); gsl_vector_set ( v, 1, 5 ); gauss = GaussianMatrix ( v, 1.2 ); gint width = cairo_image_surface_get_width ( gd->init ); gint height = cairo_image_surface_get_height ( gd->init ); unsigned char *data = cairo_image_surface_get_data ( gd->init ); gsl_matrix *pic = gsl_matrix_alloc ( height, width ); for ( gint row=0; row<height; row++ ) { for ( gint col=0; col<width; col++ ) { gsl_matrix_set ( pic, row, col, data[row*width+col] ); } } gsl_matrix *res = Convolution ( pic, gauss ); gd->gauss = cairo_image_surface_create ( CAIRO_FORMAT_A8, width, height ); cairo_surface_flush ( gd->gauss ); data = cairo_image_surface_get_data ( gd->gauss ); gint stride = cairo_image_surface_get_stride( gd->gauss ); for ( gint row=0; row<height; row++ ) { for ( gint col=0; col<width; col++ ) { data[row*stride+col] = gsl_matrix_get ( res, row, col ); } } cairo_surface_mark_dirty ( gd->gauss ); gsl_vector_free ( v ); gsl_matrix_free ( gauss ); gsl_matrix_free ( pic ); gsl_matrix_free ( res ); } gd->sCur = "高斯滤波后图片"; gd->sGauss = "已高斯滤波"; gd->cur = gd->gauss; gtk_widget_queue_draw ( gd->draw ); UpdateStatusbar (); }
void MPITest() { int rank, numNodes; Uint16 sendBuf[1], *receiveBuf; Uint16 i, j; MPI_Status status; Uint32 startTime; double elapsedTime; SEM_pend(&TestServiceSem,SYS_FOREVER); // Generate the x data for(i = 0; i < 14; i++) { for(j = 0; j < 25; j++) xglobal[i * 50 + j] = (j / 4); for(j = 0; j < 25; j++) xglobal[i * 50 + j + 25] = 6 - (j / 4); } // Generate the y data for(i = 0; i < 28; i++) { for(j = 0; j < 25; j++) yglobal[i * 25 + j] = j / 2; } // Initialize MPI MPI_Init(NULL,NULL); MPI_Comm_rank(MPI_COMM_WORLD,&rank); globals.processing.sevenSegmentUpperDigit = SEVENSEG_1DASH; // Distribute the number of nodes to use if(rank == 0) { numNodes = (gpioDataRegisters.GPBDAT.bit.SWITCH1 << 3) + (gpioDataRegisters.GPBDAT.bit.SWITCH2 << 2) + (gpioDataRegisters.GPADAT.bit.SWITCH3 << 1) + (gpioDataRegisters.GPADAT.bit.SWITCH4); sendBuf[0] = numNodes; for(i = 1; i <= 6; i++) MPI_Send(sendBuf,1,MPI_SHORT,i,0,MPI_COMM_WORLD); } else { MPI_Recv((void**)(&receiveBuf),1,MPI_SHORT,0,0,MPI_COMM_WORLD,&status); numNodes = receiveBuf[0]; MemFree(receiveBuf); } MPI_Barrier(MPI_COMM_WORLD); // If this node is participating in the convolution if(rank < numNodes) { globals.processing.sevenSegmentUpperDigit = SEVENSEG_2DASH; startTime = timer0Registers.TIM.all; Convolution(xglobal,yglobal,100,100,resultglobal,numNodes); elapsedTime = TimeDifference(startTime, timer0Registers.TIM.all); // Finalize MPI if(rank == 0) { globals.processing.sevenSegmentLowerDigit = SEVENSEG_FINAL; globals.processing.sevenSegmentUpperDigit = SEVENSEG_FINAL; } else globals.processing.sevenSegmentUpperDigit = SEVENSEG_3DASH; } else { globals.processing.sevenSegmentUpperDigit = SEVENSEG_FINAL; } SEM_pend(&TestServiceSem,SYS_FOREVER); }
/* Implementation *************************************************************/ int CConvEncoder::Encode(CVector<_BINARY>& vecInputData, CVector<_BINARY>& vecOutputData) { int iOutputCounter; int iCurPunctPattern; _BYTE byStateShiftReg; /* Set output size to zero, increment it each time a new bit is encoded */ iOutputCounter = 0; /* Reset counter for puncturing and state-register */ byStateShiftReg = 0; for (int i = 0; i < iNumInBitsWithMemory; i++) { /* Update shift-register (state information) ------------------------ */ /* Shift bits in state-shift-register */ byStateShiftReg <<= 1; /* Tailbits are calculated in this loop. Check when end of vector is reached and no more bits must be added */ if (i < iNumInBits) { /* Add new bit at the beginning */ if (vecInputData[i] == TRUE) byStateShiftReg |= 1; } /* Puncturing ------------------------------------------------------- */ /* Depending on the current puncturing pattern, different numbers of output bits are generated. The state shift register "byStateShiftReg" is convoluted with the respective patterns for this bit (is done inside the convolution function) */ switch (veciTablePuncPat[i]) { case PP_TYPE_0001: /* Pattern 0001 */ vecOutputData[iOutputCounter++] = Convolution(byStateShiftReg, 0); break; case PP_TYPE_0101: /* Pattern 0101 */ vecOutputData[iOutputCounter++] = Convolution(byStateShiftReg, 0); vecOutputData[iOutputCounter++] = Convolution(byStateShiftReg, 2); break; case PP_TYPE_0011: /* Pattern 0011 */ vecOutputData[iOutputCounter++] = Convolution(byStateShiftReg, 0); vecOutputData[iOutputCounter++] = Convolution(byStateShiftReg, 1); break; case PP_TYPE_0111: /* Pattern 0111 */ vecOutputData[iOutputCounter++] = Convolution(byStateShiftReg, 0); vecOutputData[iOutputCounter++] = Convolution(byStateShiftReg, 1); vecOutputData[iOutputCounter++] = Convolution(byStateShiftReg, 2); break; case PP_TYPE_1111: /* Pattern 1111 */ vecOutputData[iOutputCounter++] = Convolution(byStateShiftReg, 0); vecOutputData[iOutputCounter++] = Convolution(byStateShiftReg, 1); vecOutputData[iOutputCounter++] = Convolution(byStateShiftReg, 2); vecOutputData[iOutputCounter++] = Convolution(byStateShiftReg, 3); break; } } /* Return number of encoded bits */ return iOutputCounter; }
gboolean RawBound01Thread ( gpointer gdata ) { GuiData *gd = GetGuiData (); if ( gd->gauss == NULL ) return TRUE; if ( gd->raw == NULL ) { gint width = cairo_image_surface_get_width ( gd->gauss ); gint height = cairo_image_surface_get_height ( gd->gauss ); gsl_matrix *pic = gsl_matrix_alloc ( height, width ); unsigned char *data = cairo_image_surface_get_data ( gd->gauss ); for ( gint row=0; row<height; row++ ) { for ( gint col=0; col<width; col++ ) { gsl_matrix_set ( pic, row, col, data[row*width+col] ); } } gsl_matrix *h = gsl_matrix_alloc ( 3, 3 ); gsl_matrix_set_all ( h, 0 ); gsl_matrix_set ( h, 0, 0, 1 ); gsl_matrix_set ( h, 0, 1, 2 ); gsl_matrix_set ( h, 0, 2, 1 ); gsl_matrix_set ( h, 2, 0, -1 ); gsl_matrix_set ( h, 2, 1, -2 ); gsl_matrix_set ( h, 2, 2, -1 ); gsl_matrix *gx = Convolution ( pic, h ); gsl_matrix_set_all ( h, 0 ); gsl_matrix_set ( h, 0, 0, 1 ); gsl_matrix_set ( h, 1, 0, 2 ); gsl_matrix_set ( h, 2, 0, 1 ); gsl_matrix_set ( h, 0, 2, -1 ); gsl_matrix_set ( h, 1, 2, -2 ); gsl_matrix_set ( h, 2, 2, -1 ); gsl_matrix *gy = Convolution ( pic, h ); gsl_matrix *raw = gsl_matrix_alloc ( height, width ); ignore -= 10; for ( gint row=0; row<height; row++ ) { for ( gint col=0; col<width; col++ ) { if ( row < ignore || col < ignore || row > height - ignore || col > width - ignore ) { gsl_matrix_set ( raw, row, col, 0 ); } else { gsl_matrix_set ( raw, row, col, pow ( gsl_matrix_get ( gx, row, col ), 2 ) + pow ( gsl_matrix_get ( gy, row, col ), 2 ) ); } } } ignore += 10; gfloat val = 0; gint start1 = 0; /* // 从右到左 for ( gint row=height/2; row<height; row++ ) { if ( gsl_matrix_get ( raw, row, width-ignore ) > val ) { val = gsl_matrix_get ( raw, row, width-ignore ); start1 = row; } } gint start2 = start1 - 1; val = gsl_matrix_get ( raw, start1-1, width-ignore-1 ); if ( val < gsl_matrix_get ( raw, start1, width-ignore-1 ) ) { val = gsl_matrix_get ( raw, start1, width-ignore-1 ); start2++; } if ( val < gsl_matrix_get ( raw, start1+1, width-ignore-1 ) ) { val = gsl_matrix_get ( raw, start1+1, width-ignore-1 ); start2++; } gsl_vector *v = gsl_vector_alloc (3); gsl_vector_set ( v, 0, start1 ); gsl_vector_set ( v, 1, width-ignore ); gsl_vector_set ( v, 2, gsl_matrix_get ( raw, start1, width-ignore ) ); gd->rawlist = g_slist_append ( gd->rawlist, v ); gsl_vector *v1 = gsl_vector_alloc (3); gsl_vector_set ( v1, 0, start2 ); gsl_vector_set ( v1, 1, width-ignore-1 ); gsl_vector_set ( v1, 2, gsl_matrix_get ( raw, start2, width-ignore-1 ) ); gd->rawlist = g_slist_append ( gd->rawlist, v1 ); */ // 从左到右 for ( gint row=height/2; row<height; row++ ) { if ( gsl_matrix_get ( raw, row, ignore ) > val ) { val = gsl_matrix_get ( raw, row, ignore ); start1 = row; } } gint start2 = start1 - 1; val = gsl_matrix_get ( raw, start1-1, ignore+1 ); if ( val < gsl_matrix_get ( raw, start1, ignore+1 ) ) { val = gsl_matrix_get ( raw, start1, ignore+1 ); start2++; } if ( val < gsl_matrix_get ( raw, start1+1, ignore+1 ) ) { val = gsl_matrix_get ( raw, start1+1, ignore+1 ); start2++; } gsl_vector *v = gsl_vector_alloc (3); gsl_vector_set ( v, 0, start1 ); gsl_vector_set ( v, 1, ignore ); gsl_vector_set ( v, 2, gsl_matrix_get ( raw, start1, ignore ) ); gd->rawlist = g_slist_append ( gd->rawlist, v ); gsl_vector *v1 = gsl_vector_alloc (3); gsl_vector_set ( v1, 0, start2 ); gsl_vector_set ( v1, 1, ignore+1 ); gsl_vector_set ( v1, 2, gsl_matrix_get ( raw, start2, ignore+1 ) ); gd->rawlist = g_slist_append ( gd->rawlist, v1 ); for ( gint w=0; w<weightlen; w++ ) { weight = weights[w]; while ( FindSinglePoint( pic, raw, width, height, &v, &v1, gd ) ); gint length = g_slist_length ( gd->rawlist ); if ( gsl_vector_get ( v1, 1 ) > width - 2*ignore ) break; for ( int i=length-1; i>1; i-- ) { gsl_vector *vv = g_slist_nth_data ( gd->rawlist, i ); gd->rawlist = g_slist_remove ( gd->rawlist, vv ); gsl_vector_free ( vv ); } v = g_slist_nth_data ( gd->rawlist, 0 ); v1 = g_slist_nth_data ( gd->rawlist, 1 ); } /* printf ( "value:%f\n", gsl_matrix_get ( raw, 1660, 51 ) ); gsl_matrix_view vview = gsl_matrix_submatrix ( raw, 1660, 45, 10, 10 ); DispMatrix ( (gsl_matrix*)&vview ); */ gd->raw = cairo_image_surface_create ( CAIRO_FORMAT_A8, width, height ); cairo_surface_flush ( gd->raw ); data = cairo_image_surface_get_data ( gd->raw ); guint len = g_slist_length ( gd->rawlist ); for ( int i=0; i<len; i++ ) { gsl_vector *v = g_slist_nth_data ( gd->rawlist, i ); data[(int)(gsl_vector_get(v,0)*width+gsl_vector_get(v,1))] = 255; } cairo_surface_mark_dirty ( gd->raw ); gsl_matrix_free ( pic ); gsl_matrix_free ( gx ); gsl_matrix_free ( gy ); gsl_matrix_free ( h ); gsl_matrix_free ( raw ); } gd->sCur = "粗边界后图片"; gd->sRaw = "已粗边界"; gd->cur = gd->raw; UpdateStatusbar (); return TRUE; }