int search(unsigned char *x, int m, unsigned char *y, int n) { int i, j, p, k, count, test; char F[256*256]; unsigned short h; int mMinus1 = m-1; BEGIN_PREPROCESSING /* Preprocessing */ preprocessing(x,m,F); for(i=0; i<m; i++) y[n+i]=x[i]; END_PREPROCESSING BEGIN_SEARCHING /* Searching */ count = 0; j = m-1; while (j < n) { h = y[j]; i = j-mMinus1; while((test=F[h]) && j>i) { j--; h = (h<<2) + y[j]; } if(j==i && test) { k=0; while(k<m && x[k]==y[i+k]) k++; if(k==m && j<=n-m) count++; } j+=m; } END_SEARCHING return count; }
float basicOCR::classify(IplImage* img, int showResult)//第二个参数主要用来控制是测试训练样本还是手写识别 { IplImage prs_image; CvMat data; CvMat* nearest=cvCreateMat(1,K,CV_32FC1); float result; //处理输入的图像 prs_image = preprocessing(img, size, size); //Set data IplImage* img32 = cvCreateImage( cvSize( size, size ), IPL_DEPTH_32F, 1 ); cvConvertScale(&prs_image, img32, 0.0039215, 0); cvGetSubRect(img32, &data, cvRect(0,0, size,size)); CvMat row_header, *row1; row1 = cvReshape( &data, &row_header, 0, 1 ); result=knn->find_nearest(row1,K,0,0,nearest,0); int accuracy=0; for(int i=0;i<K;i++) { if( (nearest->data.fl[i]) == result) accuracy++; } float pre=100*((float)accuracy/(float)K); char out = result; if(showResult==1) { printf("|\t %c \t| \t %.2f%% \t| \t %d of %d \t| \n",out,pre,accuracy,K); printf(" ------------------------------------------------------------------------\n"); } return result; }
bool JPetTaskChainExecutor::process() { if (!preprocessing(fOptions, fParamManager, fTasks)) { ERROR("Error in preprocessing"); return false; } for (auto currentTask = fTasks.begin(); currentTask != fTasks.end(); currentTask++) { JPetOptions::Options currOpts = fOptions.getOptions(); if (currentTask != fTasks.begin()) { /// Ignore the event range options for all but the first task. currOpts = JPetOptions::resetEventRange(currOpts); /// For all but the first task, /// the input path must be changed if /// the output path argument -o was given, because the input /// data for them will lay in the location defined by -o. auto outPath = currOpts.at("outputPath"); if (!outPath.empty()) { currOpts.at("inputFile") = outPath + JPetCommonTools::extractPathFromFile(currOpts.at("inputFile")) + JPetCommonTools::extractFileNameFromFullPath(currOpts.at("inputFile")); } } auto taskCurr = dynamic_cast<JPetTask*> (dynamic_cast<JPetTaskLoader*>(*currentTask)->getTask()); //auto taskCurr = std::dynamic_pointer_cast<JPetTask>((*currentTask)->getTask()); auto taskName = taskCurr->GetName(); INFO(Form("Starting task: %s", taskName)); /// @todo fix it auto taskRunnerCurr = dynamic_cast<JPetTaskIO*> (*currentTask); taskRunnerCurr->init(currOpts); taskRunnerCurr->exec(); taskRunnerCurr->terminate(); INFO(Form("Finished task: %s", taskName)); } return true; }
void ocr() { int i, filecount, x[4], y[4], temp; char* filename=(char*)calloc(50,1); IplImage scaledimage; IplImage *imgsrc; FILE *keyinfo, *keycount; keycount = fopen("./ocr_temp_data/keycount.dat","r"); fscanf(keycount, "%d", &filecount); keyinfo = fopen("./ocr_temp_data/keyinfo.dat","r"); for(i=0; i<filecount; i++) { fscanf(keyinfo, "%d\t%s\t%d %d %d %d %d %d %d %d\n", &temp, filename, &x[0], &y[0], &x[1], &y[1], &x[2], &y[2], &x[3], &y[3]); //printf("%s\n", filename); imgsrc = cvLoadImage(filename, -1); cvThreshold(imgsrc, imgsrc, 150, 255, CV_THRESH_BINARY|CV_THRESH_OTSU); scaledimage = preprocessing(imgsrc, 60, 60); //cvShowImage("scaled image", &scaledimage); //cvShowImage("Original Key", imgsrc); //cvWaitKey(0); } cvReleaseImage(&imgsrc); }
void basicOCR::test() { IplImage* src_image; IplImage prs_image; CvMat row,data; char file[255]; int i,j; int error=0; int testCount=0; for(i =0; i<classes; i++) { for( j = 50; j< 50+train_samples; j++)//五十个测试样本,计算一下错误率 { sprintf(file,"%s%d/%d%d.pbm",file_path, i, i , j); src_image = cvLoadImage(file,0); if(!src_image) { printf("Error: Cant load image %s\n", file); exit(-1); } //process file prs_image = preprocessing(src_image, size, size); float r=classify(&prs_image,0); if((int)r!=i) error++; testCount++; } } float totalerror=100*(float)error/(float)testCount; printf("测试系统误识率: %.2f%%\n", totalerror); }
int cbmc_parseoptionst::doit() { if(cmdline.isset("version")) { std::cout << CBMC_VERSION << std::endl; return 0; } // // unwinding of transition systems // if(cmdline.isset("module") || cmdline.isset("gen-interface")) { error("This version of CBMC has no support for " " hardware modules. Please use hw-cbmc."); return 1; } register_languages(); // // command line options // optionst options; get_command_line_options(options); bmct bmc(options, context, ui_message_handler); set_verbosity(bmc); set_verbosity(*this); if(cmdline.isset("preprocess")) { preprocessing(); return 0; } goto_functionst goto_functions; if(get_goto_program(options, bmc, goto_functions)) return 6; if(cmdline.isset("show-claims")) { const namespacet ns(context); show_claims(ns, get_ui(), goto_functions); return 0; } if(set_claims(goto_functions)) return 7; // do actual BMC return do_bmc(bmc, goto_functions); }
/// <summary> /// Reads the sample images and associated charaters into trainClasses and trainData respectively. /// </summary> /// <returns> Nothing. </returns> void OCR::getData() { IplImage* src_image; IplImage prs_image; CvMat row,data; char file[255]; char dataFile[255]; std::ifstream labelStream; std::ostringstream outStringStream; char ch; int i,j; for(i = 0; i < classes; i++) { //26 //Read the corresponding character for current sample being processed into ch. sprintf(dataFile,"%s%d/data.txt",file_path, i); labelStream.open(dataFile); labelStream >> ch; labelStream.close(); for( j = 0; j< train_samples; j++) { //3 //Load file //get the path of image for training into file. if(j<10) sprintf(file,"%s%d/%d0%d.pbm",file_path, i, i, j); else sprintf(file,"%s%d/%d%d.pbm",file_path, i, i, j); src_image = cvLoadImage(file,0); if(!src_image) { printf("Error: Cant load image %s\n", file); //exit(-1); } //process file prs_image = preprocessing(src_image, size, size); //Set class label cvGetRow(trainClasses, &row, i*train_samples + j); cvSet(&row, cvRealScalar(ch)); //Set data cvGetRow(trainData, &row, i*train_samples + j); IplImage* img = cvCreateImage( cvSize( size, size ), IPL_DEPTH_32F, 1 ); //convert 8 bits image to 32 float image cvConvertScale(&prs_image, img, 0.0039215, 0); cvGetSubRect(img, &data, cvRect(0,0, size,size)); CvMat row_header, *row1; //convert data matrix sizexsize to vecor row1 = cvReshape( &data, &row_header, 0, 1 ); cvCopy(row1, &row, NULL); } } }
/** funzione di callback applicata da init_db() (usabile anche esternamente, ovvio, ma aggiunge al db solo file locali!) prende un percorso (si assume che punti ad un file valido). Se questo è un file supportato da taglib, ne analizza i tag e inserisce i dati nel database \attention le query *non* sono generiche, nè usano il file constants.h! inoltre, poiché questi dati saranno usati per generare i percorsi virtuali, non sono ammessi metadati col carattere '/': in tal caso saranno sostituiti col carattere '_' \param db database (di tipo sqlite*, ma castato a void* per questioni di compatibilità) \param path percorso del file da analizzare e, se supportato, aggiungere al database \return 0 se non ci sono errori, -1 altrimenti \sa init_db(), esegui_query(), preprocessing() */ int add_local_file_in_db(void* db, const char* path) { warn("[add_local_file_in_db] path = `%s'\n", path); TagLib_File* tlf = taglib_file_new(path); if (!tlf) return -1; TagLib_Tag* tlt = taglib_file_tag(tlf); // automaticamente free`d char* titolo = preprocessing(taglib_tag_title(tlt)); char* artista = preprocessing(taglib_tag_artist(tlt)); char* album = preprocessing(taglib_tag_album(tlt)); char* genere = preprocessing(taglib_tag_genre(tlt)); unsigned int anno = taglib_tag_year(tlt); unsigned int traccia = taglib_tag_track(tlt); char* anno_s = calloc(5, 1); // andrà bene fino all'anno 9999 char* traccia_s = calloc(3, 1); // andrà bene fino alla traccia 99 snprintf(anno_s, 5, "%04d", anno); snprintf(traccia_s, 3, "%02d", traccia); if (esegui_query(db, "INSERT OR REPLACE INTO artista(nome_artista) values " "(%Q)", artista) == -1) return -1; if (esegui_query(db, "INSERT OR REPLACE INTO musica(titolo, nome_album," " traccia, genere, artista_nome_artista, lavoro_anno) values " "(%Q, %Q, %Q, %Q, %Q, %Q)", titolo, album, traccia_s, genere, artista, anno_s) == -1) return -1; if (esegui_query(db, "INSERT OR REPLACE INTO file(host, path, permessi," " formato, dimensioni, data_ultimo_aggiornamento, musica_titolo" ", musica_nome_album, musica_traccia, basename) values (" "'127.0.0.1', %Q, %d, %Q, %d, NULL, %Q, %Q, %Q, %Q)", path, 6, extract_extension(path), extract_size(path), titolo, album, traccia_s, extract_basename(path)) == -1) return -1; taglib_tag_free_strings(); taglib_file_free(tlf); return 0; }
void basicOCR::getData() { IplImage* src_image; IplImage prs_image; CvMat row,data; char file[255]; int i,j; //for(i =0; i<classes; i++) for (i = 32; i < 32 + classes; i++) { for ( j = 0; j < train_samples; j++) { //加载pbm格式图像,作为训练 /*if(j < 10) sprintf(file,"%s%d/%d0%d.pbm",file_path, i - 48, i - 48 , j); else sprintf(file,"%s%d/%d%d.pbm",file_path, i - 48, i - 48 , j);*/ if (i >= 48 && i <= 57) sprintf(file,"%s%d/%d.pbm",file_path, i, j); else sprintf(file,"%s%d/%d.bmp",file_path, i, j); src_image = cvLoadImage(file,0); if(!src_image) { //printf("Error: Cant load image %s\n", file); continue; //exit(-1); } //process file prs_image = preprocessing(src_image, size, size); //Set class label cvGetRow(trainClasses, &row, (i - 32)*train_samples + j); cvSet(&row, cvRealScalar(i)); //Set data cvGetRow(trainData, &row, (i - 32)*train_samples + j); IplImage* img = cvCreateImage( cvSize( size, size ), IPL_DEPTH_32F, 1 ); //convert 8 bits image to 32 float image cvConvertScale(&prs_image, img, 0.0039215, 0); cvGetSubRect(img, &data, cvRect(0,0, size,size)); CvMat row_header, *row1; //convert data matrix sizexsize to vecor row1 = cvReshape( &data, &row_header, 0, 1 ); cvCopy(row1, &row, NULL); } } }
int main() { char key; IplImage *base, *fr, *fr0; float dt; struct timeval past; inform(); preprocessing(windowname, &base, &fr, &fr0); while(1) { initialize(&past); while(explosr<criticr && !restartflag && !escflag) { cvCopy(base, fr, NULL); easyplot(fr, fr0); dt = time_interval(&past); pausestate(&past, fr); user_update(); com_update(); ball_update(dt); cvShowImage(windowname, fr); } // exit if(escflag) break; // update score if(bpc.y<0) score[1]++; else score[0]++; // restart if(restartflag) { restartflag = 0; score[0] = 0; score[1] = 0; } } // free memory cvDestroyWindow(windowname); cvReleaseImage(&base); cvReleaseImage(&fr); cvReleaseImage(&fr0); cvReleaseImage(&scoretext1); cvReleaseImage(&scoretext2); cvReleaseImage(&pausetext); cvReleaseImage(&pausefr); return 0; }
int search(unsigned char *x, int m, unsigned char *y, int n) { int i, j, p, k, count, test; char F[256*256]; unsigned short h; if(m<Q) return -1; BEGIN_PREPROCESSING /* Preprocessing */ int plen = m; if(m%Q!=0) m = m-(m%Q); int mq = m-Q+1; preprocessing(x,m,F); for(i=0; i<m; i++) y[n+i]=x[i]; END_PREPROCESSING BEGIN_SEARCHING /* Searching */ count = 0; if( !memcmp(x,y,plen) ) count++; j=m; while (j < n) { h = HASH(j); while(!F[h]) { j += mq; h = HASH(j); } i = j-m+Q; while((test=F[h]) && j>i+Q-1) { j-=Q; h = (h<<6) + HASH(j); } if(j==i && test) { k=0; i -= Q-1; while(k<plen && x[k]==y[i+k]) k++; if(k==plen && i<=n-plen) count++; } j+=m-Q+1; } END_SEARCHING return count; }
greedyCover(int p) { //preprocessing(); int run =1; while(covercount<M) { maxpole = findMax(); selectPole(maxpole); if (run==1) { if (p==1) { if (covercount> M/2) { preprocessing(); run =0; } } } } int c = cleanpoles(); int value = CountPoles(); printf("value %d, feasible? %d, cleanedup any poles? %d \n", value, isFeasible(), c); }
void BarCodeDetector::detectBarCode() { preprocessing(); linesDetection(); }
void ospml_hybrid(const float* data, int dy, int dt, int dx, const float* center, const float* theta, float* recon, int ngridx, int ngridy, int num_iter, const float* reg_pars, int num_block, const float* ind_block) { if(dy == 0 || dt == 0 || dx == 0) return; float* gridx = (float*) malloc((ngridx + 1) * sizeof(float)); float* gridy = (float*) malloc((ngridy + 1) * sizeof(float)); float* coordx = (float*) malloc((ngridy + 1) * sizeof(float)); float* coordy = (float*) malloc((ngridx + 1) * sizeof(float)); float* ax = (float*) malloc((ngridx + ngridy) * sizeof(float)); float* ay = (float*) malloc((ngridx + ngridy) * sizeof(float)); float* bx = (float*) malloc((ngridx + ngridy) * sizeof(float)); float* by = (float*) malloc((ngridx + ngridy) * sizeof(float)); float* coorx = (float*) malloc((ngridx + ngridy) * sizeof(float)); float* coory = (float*) malloc((ngridx + ngridy) * sizeof(float)); float* dist = (float*) malloc((ngridx + ngridy) * sizeof(float)); int* indi = (int*) malloc((ngridx + ngridy) * sizeof(int)); assert(coordx != NULL && coordy != NULL && ax != NULL && ay != NULL && by != NULL && bx != NULL && coorx != NULL && coory != NULL && dist != NULL && indi != NULL); int s, q, p, d, i, m, n, os; int quadrant; float theta_p, sin_p, cos_p; float mov, xi, yi; int asize, bsize, csize; float* simdata; float upd; int ind_data, ind_recon; float* sum_dist; float sum_dist2; float *E, *F, *G; int ind0, ind1, indg[8]; float totalwg, wg[8], mg[8], rg[8], gammag[8]; int subset_ind1, subset_ind2; for(i = 0; i < num_iter; i++) { simdata = (float*) calloc((dt * dy * dx), sizeof(float)); // For each slice for(s = 0; s < dy; s++) { preprocessing(ngridx, ngridy, dx, center[s], &mov, gridx, gridy); // Outputs: mov, gridx, gridy subset_ind1 = dt / num_block; subset_ind2 = subset_ind1; // For each ordered-subset num_subset for(os = 0; os < num_block + 1; os++) { if(os == num_block) { subset_ind2 = dt % num_block; } sum_dist = (float*) calloc((ngridx * ngridy), sizeof(float)); E = (float*) calloc((ngridx * ngridy), sizeof(float)); F = (float*) calloc((ngridx * ngridy), sizeof(float)); G = (float*) calloc((ngridx * ngridy), sizeof(float)); // For each projection angle for(q = 0; q < subset_ind2; q++) { p = ind_block[q + os * subset_ind1]; // Calculate the sin and cos values // of the projection angle and find // at which quadrant on the cartesian grid. theta_p = fmodf(theta[p], 2.0f * (float) M_PI); quadrant = calc_quadrant(theta_p); sin_p = sinf(theta_p); cos_p = cosf(theta_p); // For each detector pixel for(d = 0; d < dx; d++) { // Calculate coordinates xi = -ngridx - ngridy; yi = 0.5f * (1 - dx) + d + mov; calc_coords(ngridx, ngridy, xi, yi, sin_p, cos_p, gridx, gridy, coordx, coordy); // Merge the (coordx, gridy) and (gridx, coordy) trim_coords(ngridx, ngridy, coordx, coordy, gridx, gridy, &asize, ax, ay, &bsize, bx, by); // Sort the array of intersection points (ax, ay) and // (bx, by). The new sorted intersection points are // stored in (coorx, coory). Total number of points // are csize. sort_intersections(quadrant, asize, ax, ay, bsize, bx, by, &csize, coorx, coory); // Calculate the distances (dist) between the // intersection points (coorx, coory). Find the // indices of the pixels on the reconstruction grid. calc_dist(ngridx, ngridy, csize, coorx, coory, indi, dist); // Calculate simdata calc_simdata(s, p, d, ngridx, ngridy, dt, dx, csize, indi, dist, recon, simdata); // Output: simdata // Calculate dist*dist sum_dist2 = 0.0f; for(n = 0; n < csize - 1; n++) { sum_dist2 += dist[n] * dist[n]; sum_dist[indi[n]] += dist[n]; } // Update if(sum_dist2 != 0.0f) { ind_data = d + p * dx + s * dt * dx; ind_recon = s * ngridx * ngridy; upd = data[ind_data] / simdata[ind_data]; for(n = 0; n < csize - 1; n++) { E[indi[n]] -= recon[indi[n] + ind_recon] * upd * dist[n]; } } } } // Weights for inner neighborhoods. totalwg = 4 + 4 / sqrt(2); wg[0] = 1 / totalwg; wg[1] = 1 / totalwg; wg[2] = 1 / totalwg; wg[3] = 1 / totalwg; wg[4] = 1 / sqrt(2) / totalwg; wg[5] = 1 / sqrt(2) / totalwg; wg[6] = 1 / sqrt(2) / totalwg; wg[7] = 1 / sqrt(2) / totalwg; // (inner region) for(n = 1; n < ngridx - 1; n++) { for(m = 1; m < ngridy - 1; m++) { ind0 = m + n * ngridy; ind1 = ind0 + s * ngridx * ngridy; indg[0] = ind1 + 1; indg[1] = ind1 - 1; indg[2] = ind1 + ngridy; indg[3] = ind1 - ngridy; indg[4] = ind1 + ngridy + 1; indg[5] = ind1 + ngridy - 1; indg[6] = ind1 - ngridy + 1; indg[7] = ind1 - ngridy - 1; for(q = 0; q < 8; q++) { mg[q] = recon[ind1] + recon[indg[q]]; rg[q] = recon[ind1] - recon[indg[q]]; gammag[q] = 1 / (1 + fabs(rg[q] / reg_pars[1])); F[ind0] += 2 * reg_pars[0] * wg[q] * gammag[q]; G[ind0] -= 2 * reg_pars[0] * wg[q] * gammag[q] * mg[q]; } } } // Weights for edges. totalwg = 3 + 2 / sqrt(2); wg[0] = 1 / totalwg; wg[1] = 1 / totalwg; wg[2] = 1 / totalwg; wg[3] = 1 / sqrt(2) / totalwg; wg[4] = 1 / sqrt(2) / totalwg; // (top) for(m = 1; m < ngridy - 1; m++) { ind0 = m; ind1 = ind0 + s * ngridx * ngridy; indg[0] = ind1 + 1; indg[1] = ind1 - 1; indg[2] = ind1 + ngridy; indg[3] = ind1 + ngridy + 1; indg[4] = ind1 + ngridy - 1; for(q = 0; q < 5; q++) { mg[q] = recon[ind1] + recon[indg[q]]; rg[q] = recon[ind1] - recon[indg[q]]; gammag[q] = 1 / (1 + fabs(rg[q] / reg_pars[1])); F[ind0] += 2 * reg_pars[0] * wg[q] * gammag[q]; G[ind0] -= 2 * reg_pars[0] * wg[q] * gammag[q] * mg[q]; } } // (bottom) for(m = 1; m < ngridy - 1; m++) { ind0 = m + (ngridx - 1) * ngridy; ind1 = ind0 + s * ngridx * ngridy; indg[0] = ind1 + 1; indg[1] = ind1 - 1; indg[2] = ind1 - ngridy; indg[3] = ind1 - ngridy + 1; indg[4] = ind1 - ngridy - 1; for(q = 0; q < 5; q++) { mg[q] = recon[ind1] + recon[indg[q]]; rg[q] = recon[ind1] - recon[indg[q]]; gammag[q] = 1 / (1 + fabs(rg[q] / reg_pars[1])); F[ind0] += 2 * reg_pars[0] * wg[q] * gammag[q]; G[ind0] -= 2 * reg_pars[0] * wg[q] * gammag[q] * mg[q]; } } // (left) for(n = 1; n < ngridx - 1; n++) { ind0 = n * ngridy; ind1 = ind0 + s * ngridx * ngridy; indg[0] = ind1 + 1; indg[1] = ind1 + ngridy; indg[2] = ind1 - ngridy; indg[3] = ind1 + ngridy + 1; indg[4] = ind1 - ngridy + 1; for(q = 0; q < 5; q++) { mg[q] = recon[ind1] + recon[indg[q]]; rg[q] = recon[ind1] - recon[indg[q]]; gammag[q] = 1 / (1 + fabs(rg[q] / reg_pars[1])); F[ind0] += 2 * reg_pars[0] * wg[q] * gammag[q]; G[ind0] -= 2 * reg_pars[0] * wg[q] * gammag[q] * mg[q]; } } // (right) for(n = 1; n < ngridx - 1; n++) { ind0 = (ngridy - 1) + n * ngridy; ind1 = ind0 + s * ngridx * ngridy; indg[0] = ind1 - 1; indg[1] = ind1 + ngridy; indg[2] = ind1 - ngridy; indg[3] = ind1 + ngridy - 1; indg[4] = ind1 - ngridy - 1; for(q = 0; q < 5; q++) { mg[q] = recon[ind1] + recon[indg[q]]; rg[q] = recon[ind1] - recon[indg[q]]; gammag[q] = 1 / (1 + fabs(rg[q] / reg_pars[1])); F[ind0] += 2 * reg_pars[0] * wg[q] * gammag[q]; G[ind0] -= 2 * reg_pars[0] * wg[q] * gammag[q] * mg[q]; } } // Weights for corners. totalwg = 2 + 1 / sqrt(2); wg[0] = 1 / totalwg; wg[1] = 1 / totalwg; wg[2] = 1 / sqrt(2) / totalwg; // (top-left) ind0 = 0; ind1 = ind0 + s * ngridx * ngridy; indg[0] = ind1 + 1; indg[1] = ind1 + ngridy; indg[2] = ind1 + ngridy + 1; for(q = 0; q < 3; q++) { mg[q] = recon[ind1] + recon[indg[q]]; rg[q] = recon[ind1] - recon[indg[q]]; gammag[q] = 1 / (1 + fabs(rg[q] / reg_pars[1])); F[ind0] += 2 * reg_pars[0] * wg[q] * gammag[q]; G[ind0] -= 2 * reg_pars[0] * wg[q] * gammag[q] * mg[q]; } // (top-right) ind0 = (ngridy - 1); ind1 = ind0 + s * ngridx * ngridy; indg[0] = ind1 - 1; indg[1] = ind1 + ngridy; indg[2] = ind1 + ngridy - 1; for(q = 0; q < 3; q++) { mg[q] = recon[ind1] + recon[indg[q]]; rg[q] = recon[ind1] - recon[indg[q]]; gammag[q] = 1 / (1 + fabs(rg[q] / reg_pars[1])); F[ind0] += 2 * reg_pars[0] * wg[q] * gammag[q]; G[ind0] -= 2 * reg_pars[0] * wg[q] * gammag[q] * mg[q]; } // (bottom-left) ind0 = (ngridx - 1) * ngridy; ind1 = ind0 + s * ngridx * ngridy; indg[0] = ind1 + 1; indg[1] = ind1 - ngridy; indg[2] = ind1 - ngridy + 1; for(q = 0; q < 3; q++) { mg[q] = recon[ind1] + recon[indg[q]]; rg[q] = recon[ind1] - recon[indg[q]]; gammag[q] = 1 / (1 + fabs(rg[q] / reg_pars[1])); F[ind0] += 2 * reg_pars[0] * wg[q] * gammag[q]; G[ind0] -= 2 * reg_pars[0] * wg[q] * gammag[q] * mg[q]; } // (bottom-right) ind0 = (ngridy - 1) + (ngridx - 1) * ngridy; ind1 = ind0 + s * ngridx * ngridy; indg[0] = ind1 - 1; indg[1] = ind1 - ngridy; indg[2] = ind1 - ngridy - 1; for(q = 0; q < 3; q++) { mg[q] = recon[ind1] + recon[indg[q]]; rg[q] = recon[ind1] - recon[indg[q]]; gammag[q] = 1 / (1 + fabs(rg[q] / reg_pars[1])); F[ind0] += 2 * reg_pars[0] * wg[q] * gammag[q]; G[ind0] -= 2 * reg_pars[0] * wg[q] * gammag[q] * mg[q]; } q = 0; for(n = 0; n < ngridx * ngridy; n++) { G[q] += sum_dist[n]; q++; } for(n = 0; n < ngridx; n++) { for(m = 0; m < ngridy; m++) { q = m + n * ngridy; if(F[q] != 0.0) { ind0 = q + s * ngridx * ngridy; recon[ind0] = (-G[q] + sqrt(G[q] * G[q] - 8 * E[q] * F[q])) / (4 * F[q]); } } } free(sum_dist); free(E); free(F); free(G); } } free(simdata); } free(gridx); free(gridy); free(coordx); free(coordy); free(ax); free(ay); free(bx); free(by); free(coorx); free(coory); free(dist); free(indi); }
bool SceneParser::addTriangleMesh(struct basicxmlnode * elementNode, Scene * scene){ if (!elementNode) { std::cout << "SceneParser::addTriangleMesh: empty node \n"; return false; } if (std::string(elementNode->tag) != "TriangleMesh") { return false; } // read filename char * cobjFileName; if (!(cobjFileName = getattributevaluebyname(elementNode, "OBJFileName"))) { std::cerr << "SceneParser::addTriangleMesh: no file specified!" << "\n"; return false; } // build obj object std::string objFileName(cobjFileName); char * attributeValue; Vector3 translate; translate[0]=0.0;translate[1]=0.0;translate[2]=0.0; if (attributeValue = getattributevaluebyname(elementNode, "translateFromOrigin")) { if (!stringToVector3<double>(translate, attributeValue)) { return false; } } double newRadius=1.0; if (attributeValue = getattributevaluebyname(elementNode, "radius")) { if (!stringToNumber<double>(newRadius, attributeValue)) { return false; } } Material* material; struct basicxmlnode * materialNode = getchildnodebyname(elementNode, "Material"); if(materialNode) { material = getMaterialReference(materialNode, scene); } // set Texture struct basicxmlnode * textureNode = getchildnodebyname(elementNode, "Texture"); ITexture* textureImage = getTextureReference(textureNode, scene); // set Bumpmap struct basicxmlnode * bumpmapNode = getchildnodebyname(elementNode, "Bumpmap"); ITexture* bumpmap = getTextureReference(bumpmapNode, scene); Vector4 color = Vector4(1,0,0,1); double reflectionPercentage = 0; if (attributeValue = getattributevaluebyname(elementNode, "color")) { if (!stringToVector4<double>(color, attributeValue)) { return false; } } if (attributeValue = getattributevaluebyname(elementNode, "reflectionPercentage")) { if (!stringToNumber<double>(reflectionPercentage, attributeValue)) { return false; } } double refractionPercentage = 0; double refractionIndex = 1; if (attributeValue = getattributevaluebyname(elementNode, "refractionPercentage")) { if (!stringToNumber<double>(refractionPercentage, attributeValue)) { return false; } } if (attributeValue = getattributevaluebyname(elementNode, "refractionIndex")) { if (!stringToNumber<double>(refractionIndex, attributeValue)) { return false; } } Mesh *m = new Mesh(scene,0,0); scene->addMesh(m); bool readSuccess = Mesh3DReader::read(objFileName,*m); if (!readSuccess) { std::cerr << "SceneParser::addTriangleMesh: Error while importing from Obj file: "<< objFileName << "\n"; return false; } /* bool readVertexNormals = false; bool readTexture = false; readOBJFile(objFileName,m,scene,readVertexNormals,readTexture); if(!readVertexNormals) { calcVertexNormals(m); } */ preprocessing(m,newRadius,translate); for(unsigned int i=0;i<m->numberOfFaces();i++) { m->getFace(i)->setTexture(textureImage); m->getFace(i)->setBumpmap(bumpmap); m->getFace(i)->setColor(color); m->getFace(i)->setMaterial(material); m->getFace(i)->setReflectionPercentage(reflectionPercentage); m->getFace(i)->setRefractionPercentage(refractionPercentage); m->getFace(i)->setRefractionIndex(refractionIndex); } return true; }
/** * Main process function of the plugin. */ static void run(LV2_Handle instance, uint32_t n_samples) { Nrepel *self = (Nrepel *)instance; //handy variables int k; unsigned int pos; //Inform latency at run call *(self->report_latency) = (float)self->input_latency; //Reset button state (if on) if (*(self->reset_profile) == 1.f) { reset_noise_profile(self); } //Softbypass targets in case of disabled or enabled if (*(self->enable) == 0.f) { //if disabled self->wet_dry_target = 0.f; } else { //if enabled self->wet_dry_target = 1.f; } //Interpolate parameters over time softly to bypass without clicks or pops self->wet_dry += self->tau * (self->wet_dry_target - self->wet_dry) + FLT_MIN; //Parameters values /*exponential decay coefficients for envelopes and adaptive noise profiling These must take into account the hop size as explained in the following paper FFT-BASED DYNAMIC RANGE COMPRESSION*/ if (*(self->release) != 0.f) //This allows to turn off smoothing with 0 ms in order to use masking only { self->release_coeff = expf(-1000.f / (((*(self->release)) * self->samp_rate) / self->hop)); } else { self->release_coeff = 0.f; //This avoids incorrect results when moving sliders rapidly } self->amount_of_reduction_linear = from_dB(-1.f * *(self->amount_of_reduction)); self->thresholds_offset_linear = from_dB(*(self->noise_thresholds_offset)); self->whitening_factor = *(self->whitening_factor_pc) / 100.f; //main loop for processing for (pos = 0; pos < n_samples; pos++) { //Store samples int the input buffer self->in_fifo[self->read_ptr] = self->input[pos]; //Output samples in the output buffer (even zeros introduced by latency) self->output[pos] = self->out_fifo[self->read_ptr - self->input_latency]; //Now move the read pointer self->read_ptr++; //Once the buffer is full we can do stuff if (self->read_ptr >= self->fft_size) { //Reset the input buffer position self->read_ptr = self->input_latency; //----------STFT Analysis------------ //Adding and windowing the frame input values in the center (zero-phasing) for (k = 0; k < self->fft_size; k++) { self->input_fft_buffer[k] = self->in_fifo[k] * self->input_window[k]; } //----------FFT Analysis------------ //Do transform fftwf_execute(self->forward); //-----------GET INFO FROM BINS-------------- get_info_from_bins(self->fft_p2, self->fft_magnitude, self->fft_phase, self->fft_size_2, self->fft_size, self->output_fft_buffer); /////////////////////SPECTRAL PROCESSING////////////////////////// /*This section countains the specific noise reduction processing blocks but it could be replaced with any spectral processing (I'm looking at you future tinkerer) Parameters for the STFT transform can be changed at the top of this file */ //If the spectrum is not silence if (!is_empty(self->fft_p2, self->fft_size_2)) { //If adaptive noise is selected the noise is adapted in time if (*(self->adaptive_state) == 1.f) { //This has to be revised(issue 8 on github) adapt_noise(self->fft_p2, self->fft_size_2, self->noise_thresholds_p2, self->auto_thresholds, self->prev_noise_thresholds, self->s_pow_spec, self->prev_s_pow_spec, self->p_min, self->prev_p_min, self->speech_p_p, self->prev_speech_p_p); self->noise_thresholds_availables = true; } /*If selected estimate noise spectrum is based on selected portion of signal *do not process the signal */ if (*(self->noise_learn_state) == 1.f) { //MANUAL //Increase window count for rolling mean self->noise_window_count++; get_noise_statistics(self->fft_p2, self->fft_size_2, self->noise_thresholds_p2, self->noise_window_count); self->noise_thresholds_availables = true; } else { //If there is a noise profile reduce noise if (self->noise_thresholds_availables == true) { //Detector smoothing and oversubtraction preprocessing(self->thresholds_offset_linear, self->fft_p2, self->noise_thresholds_p2, self->noise_thresholds_scaled, self->smoothed_spectrum, self->smoothed_spectrum_prev, self->fft_size_2, self->bark_z, self->absolute_thresholds, self->SSF, self->release_coeff, self->spreaded_unity_gain_bark_spectrum, self->spl_reference_values, self->alpha_masking, self->beta_masking, *(self->masking), *(self->adaptive_state), self->amount_of_reduction_linear, self->transient_preserv_prev, &self->tp_window_count, &self->tp_r_mean, &self->transient_present, *(self->transient_protection)); //Supression rule spectral_gain(self->fft_p2, self->noise_thresholds_p2, self->noise_thresholds_scaled, self->smoothed_spectrum, self->fft_size_2, *(self->adaptive_state), self->Gk, *(self->transient_protection), self->transient_present); //apply gains denoised_calulation(self->fft_size, self->output_fft_buffer, self->denoised_spectrum, self->Gk); //residual signal residual_calulation(self->fft_size, self->output_fft_buffer, self->residual_spectrum, self->denoised_spectrum, self->whitening_factor, self->residual_max_spectrum, &self->whitening_window_count, self->max_decay_rate); //Ensemble the final spectrum using residual and denoised final_spectrum_ensemble(self->fft_size, self->final_spectrum, self->residual_spectrum, self->denoised_spectrum, self->amount_of_reduction_linear, *(self->residual_listen)); soft_bypass(self->final_spectrum, self->output_fft_buffer, self->wet_dry, self->fft_size); } } } /////////////////////////////////////////////////////////// //----------STFT Synthesis------------ //------------FFT Synthesis------------- //Do inverse transform fftwf_execute(self->backward); //Normalizing value for (k = 0; k < self->fft_size; k++) { self->input_fft_buffer[k] = self->input_fft_buffer[k] / self->fft_size; } //------------OVERLAPADD------------- //Windowing scaling and accumulation for (k = 0; k < self->fft_size; k++) { self->output_accum[k] += (self->output_window[k] * self->input_fft_buffer[k]) / (self->overlap_scale_factor * self->overlap_factor); } //Output samples up to the hop size for (k = 0; k < self->hop; k++) { self->out_fifo[k] = self->output_accum[k]; } //shift FFT accumulator the hop size memmove(self->output_accum, self->output_accum + self->hop, self->fft_size * sizeof(float)); //move input FIFO for (k = 0; k < self->input_latency; k++) { self->in_fifo[k] = self->in_fifo[k + self->hop]; } //------------------------------- } //if } //main loop }
void bart( float *data, int dx, int dy, int dz, float *center, float *theta, float *recon, int ngridx, int ngridy, int num_iter, int num_block, float *ind_block) { float *gridx = (float *)malloc((ngridx+1)*sizeof(float)); float *gridy = (float *)malloc((ngridy+1)*sizeof(float)); float *coordx = (float *)malloc((ngridy+1)*sizeof(float)); float *coordy = (float *)malloc((ngridx+1)*sizeof(float)); float *ax = (float *)malloc((ngridx+ngridy)*sizeof(float)); float *ay = (float *)malloc((ngridx+ngridy)*sizeof(float)); float *bx = (float *)malloc((ngridx+ngridy)*sizeof(float)); float *by = (float *)malloc((ngridx+ngridy)*sizeof(float)); float *coorx = (float *)malloc((ngridx+ngridy)*sizeof(float)); float *coory = (float *)malloc((ngridx+ngridy)*sizeof(float)); float *dist = (float *)malloc((ngridx+ngridy)*sizeof(float)); int *indi = (int *)malloc((ngridx+ngridy)*sizeof(int)); assert(coordx != NULL && coordy != NULL && ax != NULL && ay != NULL && by != NULL && bx != NULL && coorx != NULL && coory != NULL && dist != NULL && indi != NULL); int s, q, p, d, i, m, n, os; int quadrant; float theta_p, sin_p, cos_p; float mov, xi, yi; int asize, bsize, csize; float *simdata; float upd; int ind_data, ind_recon; float *sum_dist; float sum_dist2; float *update; int subset_ind1, subset_ind2; for (i=0; i<num_iter; i++) { simdata = (float *)calloc((dx*dy*dz), sizeof(float)); // For each slice for (s=0; s<dy; s++) { preprocessing(ngridx, ngridy, dz, center[s], &mov, gridx, gridy); // Outputs: mov, gridx, gridy subset_ind1 = dx/num_block; subset_ind2 = subset_ind1; // For each ordered-subset num_subset for (os=0; os<num_block+1; os++) { if (os == num_block) { subset_ind2 = dx%num_block; } sum_dist = (float *)calloc((ngridx*ngridy), sizeof(float)); update = (float *)calloc((ngridx*ngridy), sizeof(float)); // For each projection angle for (q=0; q<subset_ind2; q++) { p = ind_block[q+os*subset_ind1]; // Calculate the sin and cos values // of the projection angle and find // at which quadrant on the cartesian grid. theta_p = fmod(theta[p], 2*M_PI); quadrant = calc_quadrant(theta_p); sin_p = sinf(theta_p); cos_p = cosf(theta_p); // For each detector pixel for (d=0; d<dz; d++) { // Calculate coordinates xi = -1e6; yi = -(dz-1)/2.0+d+mov; calc_coords( ngridx, ngridy, xi, yi, sin_p, cos_p, gridx, gridy, coordx, coordy); // Merge the (coordx, gridy) and (gridx, coordy) trim_coords( ngridx, ngridy, coordx, coordy, gridx, gridy, &asize, ax, ay, &bsize, bx, by); // Sort the array of intersection points (ax, ay) and // (bx, by). The new sorted intersection points are // stored in (coorx, coory). Total number of points // are csize. sort_intersections( quadrant, asize, ax, ay, bsize, bx, by, &csize, coorx, coory); // Calculate the distances (dist) between the // intersection points (coorx, coory). Find the // indices of the pixels on the reconstruction grid. calc_dist( ngridx, ngridy, csize, coorx, coory, indi, dist); // Calculate simdata calc_simdata(p, s, d, ngridx, ngridy, dy, dz, csize, indi, dist, recon, simdata); // Output: simdata // Calculate dist*dist sum_dist2 = 0.0; for (n=0; n<csize-1; n++) { sum_dist2 += dist[n]*dist[n]; sum_dist[indi[n]] += dist[n]; } // Update if (sum_dist2 != 0.0) { ind_data = d+s*dz+p*dy*dz; upd = (data[ind_data]-simdata[ind_data])/sum_dist2; for (n=0; n<csize-1; n++) { update[indi[n]] += upd*dist[n]; } } } } m = 0; for (n = 0; n < ngridx*ngridy; n++) { if (sum_dist[n] != 0.0) { ind_recon = s*ngridx*ngridy; recon[m+ind_recon] += update[m]/sum_dist[n]; } m++; } free(sum_dist); free(update); } } free(simdata); } free(gridx); free(gridy); free(coordx); free(coordy); free(ax); free(ay); free(bx); free(by); free(coorx); free(coory); free(dist); free(indi); }
void art(const float* data, int dy, int dt, int dx, const float* center, const float* theta, float* recon, int ngridx, int ngridy, int num_iter) { if(dy == 0 || dt == 0 || dx == 0) return; float* gridx = (float*) malloc((ngridx + 1) * sizeof(float)); float* gridy = (float*) malloc((ngridy + 1) * sizeof(float)); float* coordx = (float*) malloc((ngridy + 1) * sizeof(float)); float* coordy = (float*) malloc((ngridx + 1) * sizeof(float)); float* ax = (float*) malloc((ngridx + ngridy) * sizeof(float)); float* ay = (float*) malloc((ngridx + ngridy) * sizeof(float)); float* bx = (float*) malloc((ngridx + ngridy) * sizeof(float)); float* by = (float*) malloc((ngridx + ngridy) * sizeof(float)); float* coorx = (float*) malloc((ngridx + ngridy) * sizeof(float)); float* coory = (float*) malloc((ngridx + ngridy) * sizeof(float)); float* dist = (float*) malloc((ngridx + ngridy) * sizeof(float)); int* indi = (int*) malloc((ngridx + ngridy) * sizeof(int)); float* simdata = (float*) malloc((dy * dt * dx) * sizeof(float)); assert(coordx != NULL && coordy != NULL && ax != NULL && ay != NULL && by != NULL && bx != NULL && coorx != NULL && coory != NULL && dist != NULL && indi != NULL && simdata != NULL); int s, p, d, i, n; int quadrant; float theta_p, sin_p, cos_p; float mov, xi, yi; int asize, bsize, csize; float upd; int ind_data, ind_recon; for(i = 0; i < num_iter; i++) { // initialize simdata to zero memset(simdata, 0, dy * dt * dx * sizeof(float)); preprocessing(ngridx, ngridy, dx, center[0], &mov, gridx, gridy); // Outputs: mov, gridx, gridy // For each projection angle for(p = 0; p < dt; p++) { // Calculate the sin and cos values // of the projection angle and find // at which quadrant on the cartesian grid. theta_p = fmodf(theta[p], 2.0f * (float) M_PI); quadrant = calc_quadrant(theta_p); sin_p = sinf(theta_p); cos_p = cosf(theta_p); // For each detector pixel for(d = 0; d < dx; d++) { // Calculate coordinates xi = -ngridx - ngridy; yi = 0.5f * (1 - dx) + d + mov; calc_coords(ngridx, ngridy, xi, yi, sin_p, cos_p, gridx, gridy, coordx, coordy); // Merge the (coordx, gridy) and (gridx, coordy) trim_coords(ngridx, ngridy, coordx, coordy, gridx, gridy, &asize, ax, ay, &bsize, bx, by); // Sort the array of intersection points (ax, ay) and // (bx, by). The new sorted intersection points are // stored in (coorx, coory). Total number of points // are csize. sort_intersections(quadrant, asize, ax, ay, bsize, bx, by, &csize, coorx, coory); // Calculate the distances (dist) between the // intersection points (coorx, coory). Find the // indices of the pixels on the reconstruction grid. calc_dist(ngridx, ngridy, csize, coorx, coory, indi, dist); // Calculate dist*dist float sum_dist2 = 0.0f; for(n = 0; n < csize - 1; n++) { sum_dist2 += dist[n] * dist[n]; } if(sum_dist2 != 0.0f) { // For each slice for(s = 0; s < dy; s++) { // Calculate simdata calc_simdata(s, p, d, ngridx, ngridy, dt, dx, csize, indi, dist, recon, simdata); // Output: simdata // Update ind_data = d + p * dx + s * dt * dx; ind_recon = s * ngridx * ngridy; upd = (data[ind_data] - simdata[ind_data]) / sum_dist2; for(n = 0; n < csize - 1; n++) { recon[indi[n] + ind_recon] += upd * dist[n]; } } } } } } free(gridx); free(gridy); free(coordx); free(coordy); free(ax); free(ay); free(bx); free(by); free(coorx); free(coory); free(dist); free(indi); free(simdata); }
void fbp(const float *data, int dy, int dt, int dx, const float *center, const float *theta, float *recon, int ngridx, int ngridy, const char *fname, const float *filter_par) { int s, p, d, n; int quadrant; float theta_p, sin_p, cos_p; float mov, xi, yi; int asize, bsize, csize; int ind_data, ind_recon; float *gridx, *gridy, *coordx, *coordy, *ax, *ay, *bx, *by, *coorx, *coory, *dist; int *indi; gridx = (float *)malloc((size_t)(ngridx + 1) * sizeof(float)); gridy = (float *)malloc((size_t)(ngridy + 1) * sizeof(float)); coordx = (float *)malloc((size_t)(ngridy + 1) * sizeof(float)); coordy = (float *)malloc((size_t)(ngridx + 1) * sizeof(float)); ax = (float *)malloc((size_t)(ngridx + ngridy) * sizeof(float)); ay = (float *)malloc((size_t)(ngridx + ngridy) * sizeof(float)); bx = (float *)malloc((size_t)(ngridx + ngridy) * sizeof(float)); by = (float *)malloc((size_t)(ngridx + ngridy) * sizeof(float)); coorx = (float *)malloc((size_t)(ngridx + ngridy) * sizeof(float)); coory = (float *)malloc((size_t)(ngridx + ngridy) * sizeof(float)); dist = (float *)malloc((size_t)(ngridx + ngridy) * sizeof(float)); indi = (int *)malloc((size_t)(ngridx + ngridy) * sizeof(int)); /* unused arguments: */ (void)fname; (void)filter_par; assert(coordx != NULL && coordy != NULL && ax != NULL && ay != NULL && by != NULL && bx != NULL && coorx != NULL && coory != NULL && dist != NULL && indi != NULL); /* For each slice */ for (s = 0; s < dy; s++) { preprocessing(ngridx, ngridy, dx, center[s], &mov, gridx, gridy); /* Outputs: mov, gridx, gridy */ /* For each projection angle */ for (p = 0; p < dt; p++) { /* Calculate the sin and cos values of the projection angle and find at which quadrant on the cartesian grid. */ theta_p = (float)fmod(theta[p], 2 * M_PI); quadrant = calc_quadrant(theta_p); sin_p = sinf(theta_p); cos_p = cosf(theta_p); /* For each detector pixel */ for (d = 0; d < dx; d++) { /* Calculate coordinates */ xi = (float)(-ngridx - ngridy); yi = (float)(1 - dx) / 2.0f + (float)d + mov; calc_coords(ngridx, ngridy, xi, yi, sin_p, cos_p, gridx, gridy, coordx, coordy); /* Merge the (coordx, gridy) and (gridx, coordy) */ trim_coords(ngridx, ngridy, coordx, coordy, gridx, gridy, &asize, ax, ay, &bsize, bx, by); /* Sort the array of intersection points (ax, ay) and (bx, by). The new sorted intersection points are stored in (coorx, coory). Total number of points are csize. */ sort_intersections(quadrant, asize, ax, ay, bsize, bx, by, &csize, coorx, coory); /* Calculate the distances (dist) between the intersection points (coorx, coory). Find the indices of the pixels on the reconstruction grid. */ calc_dist(ngridx, ngridy, csize, coorx, coory, indi, dist); /* Update */ ind_recon = s * ngridx * ngridy; ind_data = d + p * dx + s * dt * dx; for (n = 0; n < csize - 1; n++) { recon[indi[n] + ind_recon] += data[ind_data] * dist[n]; } } } } free(gridx); free(gridy); free(coordx); free(coordy); free(ax); free(ay); free(bx); free(by); free(coorx); free(coory); free(dist); free(indi); }
void fbp( float *data, int dx, int dy, int dz, float *center, float *theta, float *recon, int ngridx, int ngridy, char *fname, int istart, int iend) { float *gridx = (float *)malloc((ngridx+1)*sizeof(float)); float *gridy = (float *)malloc((ngridy+1)*sizeof(float)); float *coordx = (float *)malloc((ngridy+1)*sizeof(float)); float *coordy = (float *)malloc((ngridx+1)*sizeof(float)); float *ax = (float *)malloc((ngridx+ngridy)*sizeof(float)); float *ay = (float *)malloc((ngridx+ngridy)*sizeof(float)); float *bx = (float *)malloc((ngridx+ngridy)*sizeof(float)); float *by = (float *)malloc((ngridx+ngridy)*sizeof(float)); float *coorx = (float *)malloc((ngridx+ngridy)*sizeof(float)); float *coory = (float *)malloc((ngridx+ngridy)*sizeof(float)); float *dist = (float *)malloc((ngridx+ngridy)*sizeof(float)); int *indi = (int *)malloc((ngridx+ngridy)*sizeof(int)); assert(coordx != NULL && coordy != NULL && ax != NULL && ay != NULL && by != NULL && bx != NULL && coorx != NULL && coory != NULL && dist != NULL && indi != NULL); int s, p, d, n; int quadrant; float theta_p, sin_p, cos_p; float mov, xi, yi; int asize, bsize, csize; float* simdata; int ind_data, ind_recon; simdata = (float *)calloc((dx*dy*dz), sizeof(float)); // For each slice for (s=istart; s<iend; s++) { preprocessing(ngridx, ngridy, dz, center[s], &mov, gridx, gridy); // Outputs: mov, gridx, gridy // For each projection angle for (p=0; p<dx; p++) { // Calculate the sin and cos values // of the projection angle and find // at which quadrant on the cartesian grid. theta_p = fmod(theta[p], 2*M_PI); quadrant = calc_quadrant(theta_p); sin_p = sinf(theta_p); cos_p = cosf(theta_p); // For each detector pixel for (d=0; d<dz; d++) { // Calculate coordinates xi = -ngridx-ngridy; yi = (1-dz)/2.0+d+mov; calc_coords( ngridx, ngridy, xi, yi, sin_p, cos_p, gridx, gridy, coordx, coordy); // Merge the (coordx, gridy) and (gridx, coordy) trim_coords( ngridx, ngridy, coordx, coordy, gridx, gridy, &asize, ax, ay, &bsize, bx, by); // Sort the array of intersection points (ax, ay) and // (bx, by). The new sorted intersection points are // stored in (coorx, coory). Total number of points // are csize. sort_intersections( quadrant, asize, ax, ay, bsize, bx, by, &csize, coorx, coory); // Calculate the distances (dist) between the // intersection points (coorx, coory). Find the // indices of the pixels on the reconstruction grid. calc_dist( ngridx, ngridy, csize, coorx, coory, indi, dist); // Calculate simdata calc_simdata(p, s, d, ngridx, ngridy, dy, dz, csize, indi, dist, recon, simdata); // Output: simdata // Calculate dist*dist float sum_dist2 = 0.0; for (n=0; n<csize-1; n++) { sum_dist2 += dist[n]*dist[n]; } // Update if (sum_dist2 != 0.0) { ind_recon = s*ngridx*ngridy; ind_data = d+s*dz+p*dy*dz; for (n=0; n<csize-1; n++) { recon[indi[n]+ind_recon] += data[ind_data]*dist[n]; } } } } } free(simdata); free(gridx); free(gridy); free(coordx); free(coordy); free(ax); free(ay); free(bx); free(by); free(coorx); free(coory); free(dist); free(indi); }
void FrameGrabber<Camera>:: processNextFrame() { frame_data.nextFrame(); per_mon_->start("grab frame"); if (!params_.livestream) { FrameBundle bundle; while (file_grabber_mon_.getFrameBundle(frame_data.frame_id, &bundle) ==false) { } if (params_.color_img) { frame_data.cur_left().color_uint8 = bundle.left_color; cv::cvtColor(frame_data.cur_left().color_uint8, frame_data.cur_left().uint8, CV_BGR2GRAY); } else { frame_data.cur_left().uint8 = bundle.left_gray; } if (params_.disp_img) { cv::Mat float_as_4uint = bundle.disp; frame_data.disp = cv::Mat(frame_data.cur_left().uint8.size(), CV_32F, float_as_4uint.data).clone(); cerr << frame_data.disp.size().width << " " << frame_data.disp.size().height << endl; frame_data.have_disp_img = true; } else if (params_.depth_img) { //frame_data.right.uint8 = cv::imread(right_sstr.str(),0); cv::Mat depth = bundle.depth; depthToDisp(depth, &frame_data.disp); frame_data.have_disp_img = true; } else if (params_.right_img) { frame_data.right.uint8 = bundle.right; } if (params_.rectify_frame) rectifyFrame(); } else { frameFromLiveCamera(); } per_mon_->stop("grab frame"); preprocessing(); ++frame_data.frame_id; }
int search(unsigned char *x, int m, unsigned char *y, int n) { int i, j, p, b, lf, count, test, kmpNext[XSIZE]; int tp, st; char F[256*256]; unsigned short h; if(m<Q) return -1; BEGIN_PREPROCESSING /* Preprocessing */ preKmp(x, m, kmpNext); int plen = m; if(m%Q!=0) m = m-(m%Q); int mm1 = m-1; int mq = m-Q+1; preprocessing(x,m,F); for(i=0; i<m; i++) y[n+i]=x[i]; END_PREPROCESSING BEGIN_SEARCHING /* Searching */ count = 0; tp = 0; st = 0; if( !memcmp(x,y,plen) ) count++; j=m; while (j < n) { h = HASH(j); while(!F[h]) { j += mq; h = HASH(j); } lf = b = j-m+Q; if(b<tp) b=tp-1; //b is the maximum between lf and tp-1 while((test=F[h]) && j>b) { j-=Q; h = (h<<10) + HASH(j); } // verification if(j<=b && test) { lf -= Q-1; if(lf>tp) { //restart kmp aut tp = lf; st = 0; } while(st >= tp-lf) { while(st<plen && x[st]==y[tp]) { st++; tp++; } if (st == plen && lf<=n-plen) count++; st = kmpNext[st]; if(st<0) { st++; tp++; } } j = tp+mm1-st; } else j+=m-Q+1; } END_SEARCHING return count; }
void project( float *obj, int ox, int oy, int oz, float *data, int dx, int dy, int dz, float *center, float *theta, int istart, int iend) { float *gridx = (float *)malloc((oy+1)*sizeof(float)); float *gridy = (float *)malloc((oz+1)*sizeof(float)); float *coordx = (float *)malloc((oz+1)*sizeof(float)); float *coordy = (float *)malloc((oy+1)*sizeof(float)); float *ax = (float *)malloc((oy+oz)*sizeof(float)); float *ay = (float *)malloc((oy+oz)*sizeof(float)); float *bx = (float *)malloc((oy+oz)*sizeof(float)); float *by = (float *)malloc((oy+oz)*sizeof(float)); float *coorx = (float *)malloc((oy+oz)*sizeof(float)); float *coory = (float *)malloc((oy+oz)*sizeof(float)); float *dist = (float *)malloc((oy+oz)*sizeof(float)); int *indi = (int *)malloc((oy+oz)*sizeof(int)); assert(coordx != NULL && coordy != NULL && ax != NULL && ay != NULL && by != NULL && bx != NULL && coorx != NULL && coory != NULL && dist != NULL && indi != NULL); int s, p, d; int quadrant; float theta_p, sin_p, cos_p; float mov, xi, yi; int asize, bsize, csize; preprocessing(oy, oz, dz, center[0], &mov, gridx, gridy); // Outputs: mov, gridx, gridy // For each projection angle for (p=istart; p<iend; p++) { // Calculate the sin and cos values // of the projection angle and find // at which quadrant on the cartesian grid. theta_p = fmod(theta[p], 2*M_PI); quadrant = calc_quadrant(theta_p); sin_p = sinf(theta_p); cos_p = cosf(theta_p); for (d=0; d<dz; d++) { // Calculate coordinates xi = -oy-oz; yi = (1-dz)/2.0+d+mov; calc_coords( oy, oz, xi, yi, sin_p, cos_p, gridx, gridy, coordx, coordy); // Merge the (coordx, gridy) and (gridx, coordy) trim_coords( oy, oz, coordx, coordy, gridx, gridy, &asize, ax, ay, &bsize, bx, by); // Sort the array of intersection points (ax, ay) and // (bx, by). The new sorted intersection points are // stored in (coorx, coory). Total number of points // are csize. sort_intersections( quadrant, asize, ax, ay, bsize, bx, by, &csize, coorx, coory); // Calculate the distances (dist) between the // intersection points (coorx, coory). Find the // indices of the pixels on the object grid. calc_dist( oy, oz, csize, coorx, coory, indi, dist); // For each slice for (s=0; s<dy; s++) { // Calculate simdata calc_simdata(p, s, d, oy, oz, dy, dz, csize, indi, dist, obj, data); // Output: simulated data } } } free(gridx); free(gridy); free(coordx); free(coordy); free(ax); free(ay); free(bx); free(by); free(coorx); free(coory); free(dist); free(indi); }
int main(int argc, char *argv[]) { byte *stream; long n; char *strings, *queryString, *string; char **allwords, **uniquewords; int i, nwords, maxlength, newwords; double **allvectors, **A, **query; if (argc != NARGS) { printf("usage: %s filename\n", argv[PROGNAME]); return -1; } printf("READING INPUT FILE...\n"); stream = readFullFile(argv[FILENAME], &n); printf("PREPROCESSING...\n"); strings = preprocessing(stream, n); printf("preprocessed: %s\n\n", strings); printf("EXTRACTING WORDS...\n"); allwords = words(strings, &nwords); for (i = 0; i < nwords; i++) { printf("%s\n", allwords[i]); } printf("NORMALIZING WORDS...\n"); maxlength = normalize(allwords, nwords); printf("EXTRACTING UNIQUE WORDS...\n"); uniquewords = unique(allwords, nwords, &newwords); printf("PREPARING THE VECTORS {+1,-1}...\n"); allvectors = vectors(uniquewords, newwords, maxlength); printf("GENERATING MATRIX A...\n"); A = bam_training(allvectors, newwords, maxlength*BITS_IN_BYTE); query = (double **) malloc(sizeof(double *)); // query (double **) // | // ----> double * while (1) { printf("Type a word: "); queryString = readLine(maxlength); printf("Word: %s\n", queryString); if (strcmp(queryString, "q") == 0) { free(queryString); break; } query[FIRST_ROW] = char2vec(queryString, maxlength); string = bam_testing(A, maxlength*BITS_IN_BYTE, maxlength*BITS_IN_BYTE, query); printf("Did you mean '%s'?\n", string); free(query[FIRST_ROW]); free(queryString); free(string); } free(query); free(stream); free(strings); for (i = 0; i < nwords; i++) free(allwords[i]); free(allwords); for (i = 0; i < newwords; i++) free(uniquewords[i]); free(uniquewords); matrix_free(allvectors, newwords); matrix_free(A, maxlength * BITS_IN_BYTE); return 0; }
int cbmc_parse_optionst::doit() { if(cmdline.isset("version")) { std::cout << CBMC_VERSION << std::endl; return 0; } // // command line options // optionst options; get_command_line_options(options); eval_verbosity(); // // Print a banner // status() << "CBMC version " CBMC_VERSION " " << sizeof(void *)*8 << "-bit " << config.this_architecture() << " " << config.this_operating_system() << eom; // // Unwinding of transition systems is done by hw-cbmc. // if(cmdline.isset("module") || cmdline.isset("gen-interface")) { error() << "This version of CBMC has no support for " " hardware modules. Please use hw-cbmc." << eom; return 1; } register_languages(); if(cmdline.isset("test-preprocessor")) return test_c_preprocessor(ui_message_handler)?8:0; if(cmdline.isset("preprocess")) { preprocessing(); return 0; } goto_functionst goto_functions; // get solver cbmc_solverst cbmc_solvers(options, symbol_table, ui_message_handler); cbmc_solvers.set_ui(get_ui()); std::unique_ptr<cbmc_solverst::solvert> cbmc_solver; try { cbmc_solver=cbmc_solvers.get_solver(); } catch(const char *error_msg) { error() << error_msg << eom; return 1; } prop_convt &prop_conv=cbmc_solver->prop_conv(); bmct bmc(options, symbol_table, ui_message_handler, prop_conv); int get_goto_program_ret= get_goto_program(options, bmc, goto_functions); if(get_goto_program_ret!=-1) return get_goto_program_ret; label_properties(goto_functions); if(cmdline.isset("show-claims") || // will go away cmdline.isset("show-properties")) // use this one { const namespacet ns(symbol_table); show_properties(ns, get_ui(), goto_functions); return 0; } if(cmdline.isset("show-reachable-properties")) // may replace --show-properties { const namespacet ns(symbol_table); // Entry point will have been set before and function pointers removed status() << "Removing Unused Functions" << eom; remove_unused_functions(goto_functions, ui_message_handler); show_properties(ns, get_ui(), goto_functions); return 0; } if(set_properties(goto_functions)) return 7; if(cmdline.isset("danger")) return run_danger(options, result(), symbol_table, goto_functions); if(cmdline.isset("safety")) return run_safety(options, result(), symbol_table, goto_functions); // do actual BMC return do_bmc(bmc, goto_functions); }