void sampler_adaptive::adapt(double *p, const double *a, const double *b, const double *c, const double *d, int r) { double v[3]; double va[3], pa[4]; double vb[3], pb[4]; double vc[3], pc[4]; double vd[3], pd[4]; mid4(v, a, b, c, d); mid2(va, v, a); mid2(vb, v, b); mid2(vc, v, c); mid2(vd, v, d); source->get(pa, va); source->get(pb, vb); source->get(pc, vc); source->get(pd, vd); if (r < 4) { if (contrast(pa[0], pb[0], pc[0], pd[0]) > kr || contrast(pa[1], pb[1], pc[1], pd[1]) > kg || contrast(pa[2], pb[2], pc[2], pd[2]) > kb) { double n[3]; double s[3]; double e[3]; double w[3]; mid2(n, a, b); mid2(s, c, d); mid2(e, a, c); mid2(w, b, d); adapt(pa, a, n, e, v, r + 1); adapt(pb, n, b, v, w, r + 1); adapt(pc, e, v, c, s, r + 1); adapt(pd, v, w, s, d, r + 1); } } switch (source->getc()) { case 4: p[3] = (pa[3] + pb[3] + pc[3] + pd[3]) / 4; case 3: p[2] = (pa[2] + pb[2] + pc[2] + pd[2]) / 4; case 2: p[1] = (pa[1] + pb[1] + pc[1] + pd[1]) / 4; case 1: p[0] = (pa[0] + pb[0] + pc[0] + pd[0]) / 4; } }
void KQtTester::testImageEffects() { QString report = QString("execute %1 times:\n").arg(g_nTimes); report += QString("none:\t%1\tms\n").arg(none()); m_pPainter->translate(g_img.width() + 10, 0); report += QString("gray:\t%1\tms\n").arg(gray()); m_pPainter->translate(g_img.width() + 10, 0); report += QString("watermark:\t%1\tms\n").arg(watermark()); m_pPainter->translate(g_img.width() + 10, 0); report += QString("bilevel:\t%1\tms\n").arg(bilevel()); m_pPainter->resetMatrix(); m_pPainter->translate(0, g_img.height() + 10); report += QString("lightBlue:\t%1\tms\n").arg(lightBlue()); m_pPainter->translate(g_img.width() + 10, 0); report += QString("darkBlue:\t%1\tms\n").arg(darkBlue()); m_pPainter->resetMatrix(); m_pPainter->translate(0, (g_img.height() + 10) * 2); report += QString("colorKey:\t%1\tms\n").arg(colorKey()); m_pPainter->translate(g_img.width() + 10, 0); report += QString("brightness:\t%1\tms\n").arg(brightness()); m_pPainter->translate(g_img.width() + 10, 0); report += QString("contrast:\t%1\tms\n").arg(contrast()); m_pPainter->translate(g_img.width() + 10, 0); report += QString("brown:\t%1\tms\n").arg(brown()); drawReport(report); }
float PropagatedDeformableModel::computeContrast(Referential& refInitial) { // Calcul du profil de la moelle et du LCR perpendiculairement au tube CVector3 pointS, indexS; vector<float> contrast(resolutionRadiale_); float angle; CMatrix3x3 trZ; CMatrix4x4 transformationFromOrigin = refInitial.getTransformationInverse(); float factor = image3D_->getTypeImageFactor(); for (int k=0; k<resolutionRadiale_; k++) { vector<float> profilIntensite; angle = 2*M_PI*k/(double)resolutionRadiale_; trZ[0] = cos(angle), trZ[1] = sin(angle), trZ[3] = -sin(angle), trZ[4] = cos(angle); for (int l=0; l<2.5*rayon_; l++) { pointS = transformationFromOrigin*(trZ*CVector3(l,0.0,0.0)); if (image3D_->TransformPhysicalPointToIndex(pointS,indexS)) profilIntensite.push_back(factor*image3D_->GetPixelOriginal(indexS)); } float min = 0.0, max = 0.0, maxVal = 0.0, valCourante; unsigned int m = 0; for (unsigned int i=1; i<profilIntensite.size(); i++) { valCourante = profilIntensite[i]-profilIntensite[i-1]; if (maxVal <= valCourante) { maxVal = valCourante; m = i; } } if (profilIntensite.size() > 0) { min = profilIntensite[m]; for (unsigned int j=0; j<m; j++) { valCourante = profilIntensite[j]; if (min > valCourante) min = valCourante; } max = profilIntensite[m]; for (unsigned int j=m+1; j<profilIntensite.size(); j++) { valCourante = profilIntensite[j]; if (max < valCourante) max = valCourante; } } contrast[k] = abs(max-min); } float result = 0.0; for (unsigned int i=0; i<contrast.size(); i++) result += contrast[i]; result /= contrast.size(); return result; }
/* Tamura3Sigs vec -array of double- a pre-allocated array of 6 doubles */ void Tamura3Sigs2D(ImageMatrix *Im, double *vec) { double temp[6]; temp[0]=coarseness(Im,&(temp[1]),3); temp[4]=directionality(Im); temp[5]=contrast(Im); /* rearange the order of the value so it will fit OME */ vec[0]=temp[1]; vec[1]=temp[2]; vec[2]=temp[3]; vec[3]=temp[5]; vec[4]=temp[4]; vec[5]=temp[0]; }
QVariant S60CameraImageProcessingControl::processingParameter( QCameraImageProcessingControl::ProcessingParameter parameter) const { switch (parameter) { case QCameraImageProcessingControl::Contrast: return QVariant(contrast()); case QCameraImageProcessingControl::Saturation: return QVariant(saturation()); case QCameraImageProcessingControl::Brightness: return QVariant(brightness()); case QCameraImageProcessingControl::Sharpening: return QVariant(sharpeningLevel()); case QCameraImageProcessingControl::Denoising: return QVariant(denoisingLevel()); case QCameraImageProcessingControl::ColorTemperature: return QVariant(manualWhiteBalance()); default: return QVariant(); } }
int bcf_p1_cal(bcf1_t *b, bcf_p1aux_t *ma, bcf_p1rst_t *rst) { int i, k; long double sum = 0.; // set PL and PL_len for (i = 0; i < b->n_gi; ++i) { if (b->gi[i].fmt == bcf_str2int("PL", 2)) { ma->PL = (uint8_t*)b->gi[i].data; ma->PL_len = b->gi[i].len; break; } } if (b->n_alleles < 2) return -1; // FIXME: find a better solution // rst->rank0 = cal_pdg(b, ma); rst->f_exp = mc_cal_afs(ma); rst->p_ref = ma->afs1[ma->M]; // calculate f_flat and f_em for (k = 0, sum = 0.; k <= ma->M; ++k) sum += (long double)ma->z[k]; rst->f_flat = 0.; for (k = 0; k <= ma->M; ++k) { double p = ma->z[k] / sum; rst->f_flat += k * p; } rst->f_flat /= ma->M; { // calculate f_em double flast = rst->f_flat; for (i = 0; i < MC_MAX_EM_ITER; ++i) { rst->f_em = mc_freq_iter(flast, ma); if (fabs(rst->f_em - flast) < MC_EM_EPS) break; flast = rst->f_em; } } rst->g[0] = rst->g[1] = rst->g[2] = -1.; contrast(ma, rst->pc); return 0; }
int ImageViewer::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QMainWindow::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: open(); break; case 1: save(); break; case 2: saveAs(); break; case 3: contrast(); break; case 4: per_channel(); break; case 5: from_user_gaus_filter(); break; case 6: unsharp_filter(); break; case 7: scale(); break; case 8: rotate(); break; case 9: gray_world(); break; default: ; } _id -= 10; } return _id; }
int ColormapEdit::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QDialog::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: newColorList((*reinterpret_cast< QList<QColor>(*)>(_a[1]))); break; case 1: rotate((*reinterpret_cast< int(*)>(_a[1]))); break; case 2: bias((*reinterpret_cast< int(*)>(_a[1]))); break; case 3: contrast((*reinterpret_cast< int(*)>(_a[1]))); break; case 4: setColor(); break; case 5: okPressed(); break; case 6: applyPressed(); break; case 7: biasReset(); break; case 8: rotateReset(); break; case 9: contrastRest(); break; case 10: updateColormap(); break; case 11: resetMap((*reinterpret_cast< int(*)>(_a[1]))); break; } _id -= 12; } return _id; }
int main(int argc, char *argv[]) { PICTURE *pic; int bperc = 5, wperc = 5, sz; vmessage(); switch (argc) { case 5: wperc = atoi(argv[4]); case 4: bperc = atoi(argv[3]); case 3: case 2: dofiles(argc,argv); /* fprintf(stderr,"%s %d %d %s %s\n",PROGNAME,bperc,wperc,FILEIN,FILEOUT); */ break; default: (void)fprintf(stderr, "usage: contrast infile outfile [blackpercent][whitepercent]\n"); exit(1); } if ((pic = readpic(FILEIN)) == NULL) exit(1); if ((pic->fileid) != IMAGE_ID) { (void)fprintf(stderr,"%s: wrong type of input file\n",PROGNAME); exit(1); } sz = (pic->items)*(pic->samples); contrast(pic,bperc*sz/100,wperc*sz/100); writepmpic(pic,FILEOUT); exit(0); }
int runFilter(int argc, char *argv[]) { char * filenameInput=argv[1]; char * filenameOutput=argv[2]; unsigned int inputType = guessFilenameTypeStupid(filenameInput); struct Image * inputImage = readImage(filenameInput,inputType,0); struct Image * outputImage = 0; //This will get allocated when and if needed if (inputImage!=0) { unsigned int outputType = guessFilenameTypeStupid(filenameOutput); unsigned int i=0; for (i=0; i<argc; i++) { if ( strcmp(argv[i],"--learn")==0 ) { destroyImage(inputImage); learnImage(filenameInput,atoi(argv[i+1]),atoi(argv[i+2])); exit(0); } else if ( strcmp(argv[i],"--rgbcube")==0 ) { unsigned int dim=32; unsigned char R = (char) atoi(argv[i]+1); unsigned char G = (char) atoi(argv[i]+2); unsigned char B = (char) atoi(argv[i]+3); outputImage = createImage( dim , dim , 3 , 8 ); bitbltColorRGB(outputImage->pixels , 0 , 0 , dim , dim , R , G , B , dim-1 , dim-1); writeImageFile(outputImage,PPM_CODEC ,"new_mX.pnm"); writeImageFile(outputImage,PPM_CODEC ,"new_pX.pnm"); writeImageFile(outputImage,PPM_CODEC ,"new_mY.pnm"); writeImageFile(outputImage,PPM_CODEC ,"new_pY.pnm"); writeImageFile(outputImage,PPM_CODEC ,"new_mZ.pnm"); writeImageFile(outputImage,PPM_CODEC ,"new_pZ.pnm"); destroyImage(outputImage); } else if ( strcmp(argv[i],"--envcube")==0 ) { fprintf(stdout,"Converting Environment Cube \n"); unsigned int outputType = guessFilenameTypeStupid(filenameOutput); //outputImage = createSameDimensionsImage(inputImage); unsigned int outputWidth = inputImage->width; unsigned int outputHeight = (unsigned int ) (3*inputImage->width)/4; outputImage = createImage( outputWidth , outputHeight , 3 , 8 ); createCubeMapFace( outputImage->pixels , outputImage->width , outputImage->height , outputImage->channels , outputImage->bitsperpixel , inputImage->pixels , inputImage->width , inputImage->height , inputImage->channels , inputImage->bitsperpixel ); struct Image * partImg=0; unsigned int outX=0 , outY=0 , outWidth=0 , outHeight=0; getCubeMap2DCoords(outputWidth,outputHeight, /*x*/ -1 , /*y*/ 0 , /*z*/ 0 , &outX , &outY , &outWidth , &outHeight ); partImg=createImageBitBlt( outputImage , outX , outY , outWidth , outHeight ); writeImageFile(partImg,PPM_CODEC ,"new_mX.pnm"); destroyImage(partImg); getCubeMap2DCoords(outputWidth,outputHeight, /*x*/ 1 , /*y*/ 0 , /*z*/ 0 , &outX , &outY , &outWidth , &outHeight ); partImg=createImageBitBlt( outputImage , outX , outY , outWidth , outHeight ); writeImageFile(partImg,PPM_CODEC ,"new_pX.pnm"); destroyImage(partImg); getCubeMap2DCoords(outputWidth,outputHeight, /*x*/ 0 , /*y*/ -1 , /*z*/ 0 , &outX , &outY , &outWidth , &outHeight ); partImg=createImageBitBlt( outputImage , outX , outY , outWidth , outHeight ); writeImageFile(partImg,PPM_CODEC ,"new_mY.pnm"); destroyImage(partImg); getCubeMap2DCoords(outputWidth,outputHeight, /*x*/ 0 , /*y*/ 1 , /*z*/ 0 , &outX , &outY , &outWidth , &outHeight ); partImg=createImageBitBlt( outputImage , outX , outY , outWidth , outHeight ); writeImageFile(partImg,PPM_CODEC ,"new_pY.pnm"); destroyImage(partImg); getCubeMap2DCoords(outputWidth,outputHeight, /*x*/ 0 , /*y*/ 0 , /*z*/ -1 , &outX , &outY , &outWidth , &outHeight ); partImg=createImageBitBlt( outputImage , outX , outY , outWidth , outHeight ); writeImageFile(partImg,PPM_CODEC ,"new_mZ.pnm"); destroyImage(partImg); getCubeMap2DCoords(outputWidth,outputHeight, /*x*/ 0 , /*y*/ 0 , /*z*/ 1 , &outX , &outY , &outWidth , &outHeight ); partImg=createImageBitBlt( outputImage , outX , outY , outWidth , outHeight ); writeImageFile(partImg,PPM_CODEC ,"new_pZ.pnm"); destroyImage(partImg); } else if ( strcmp(argv[i],"--compare")==0 ) { unsigned int outputType = guessFilenameTypeStupid(filenameOutput); outputImage = readImage(filenameOutput,outputType ,0); float noise = calculatePSNR( outputImage->pixels , outputImage->width , outputImage->height , outputImage->channels , inputImage->pixels , inputImage->width , inputImage->height , inputImage->channels ); fprintf(stdout,"Compared Detected Noise is %0.4f dB \n",noise); exit(0); } else if ( strcmp(argv[i],"--gaussian")==0 ) { monochrome(inputImage); outputImage = createSameDimensionsImage(inputImage); unsigned int normalizeGaussianKernel=1; unsigned int kernelWidth=5; unsigned int kernelHeight=5; float * convolutionMatrix=allocateGaussianKernel(kernelWidth,kernelHeight,normalizeGaussianKernel); float divisor=1.0; float * inF = copyUCharImage2Float(inputImage->pixels , inputImage->width , inputImage->height , inputImage->channels ); float * outF = (float*) malloc(sizeof(float) * outputImage->width * outputImage->height * outputImage->channels ); convolutionFilter1ChF( outF , outputImage->width , outputImage->height , inF, inputImage->width , inputImage->height , convolutionMatrix , kernelWidth , kernelHeight , &divisor ); free(convolutionMatrix); castFloatImage2UChar(outputImage->pixels, outF, outputImage->width , outputImage->height , outputImage->channels ); free(inF); free(outF); } else if ( strcmp(argv[i],"--ctbilateral")==0 ) { monochrome(inputImage); outputImage = createSameDimensionsImage(inputImage); float sigma = atof(argv[i+1]); constantTimeBilateralFilter( inputImage->pixels , inputImage->width , inputImage->height , inputImage->channels , outputImage->pixels , outputImage->width , outputImage->height ,&sigma //sigma ,atoi(argv[i+2]) //bins ,atoi(argv[i+3]) //useDeriche ); } else if ( strcmp(argv[i],"--deriche")==0 ) { monochrome(inputImage); outputImage = createSameDimensionsImage(inputImage); float sigma = atof(argv[i+1]); dericheRecursiveGaussianGray( outputImage->pixels , outputImage->width , outputImage->height , inputImage->channels , inputImage->pixels , inputImage->width , inputImage->height , &sigma , atoi(argv[i+2]) ); } else if ( strcmp(argv[i],"--dericheF")==0 ) { fprintf(stderr,"This is a test call for casting code , this shouldnt be normally used..\n"); monochrome(inputImage); outputImage = createSameDimensionsImage(inputImage); float sigma = atof(argv[i+1]); //outputImage = copyImage(inputImage); float * inF = copyUCharImage2Float(inputImage->pixels , inputImage->width , inputImage->height , inputImage->channels ); float * outF = (float*) malloc(sizeof(float) * outputImage->width * outputImage->height * outputImage->channels ); dericheRecursiveGaussianGrayF( outF , outputImage->width , outputImage->height , inputImage->channels , inF , inputImage->width , inputImage->height , &sigma , atoi(argv[i+2]) ); castFloatImage2UChar(outputImage->pixels, outF, outputImage->width , outputImage->height , outputImage->channels ); free(inF); free(outF); } else if ( strcmp(argv[i],"--median")==0 ) { outputImage = copyImage(inputImage); medianFilter3ch( outputImage->pixels , outputImage->width , outputImage->height , inputImage->pixels , inputImage->width , inputImage->height , atoi(argv[i+1]) , atoi(argv[i+2]) ); } else if ( strcmp(argv[i],"--meansat")==0 ) { outputImage = copyImage(inputImage); meanFilterSAT( outputImage->pixels , outputImage->width , outputImage->height , outputImage->channels , inputImage->pixels , inputImage->width , inputImage->height , inputImage->channels , atoi(argv[i+1]) , atoi(argv[i+2]) ); } else if ( strcmp(argv[i],"--monochrome")==0 ) { outputImage = copyImage(inputImage); monochrome(outputImage); } else if ( strcmp(argv[i],"--bilateral")==0 ) { outputImage = copyImage(inputImage); bilateralFilter( outputImage->pixels , outputImage->width , outputImage->height , inputImage->pixels , inputImage->width , inputImage->height , atof(argv[i+1]) , atof(argv[i+2]) , atoi(argv[i+3]) ); } else if ( strcmp(argv[i],"--contrast")==0 ) { outputImage = copyImage(inputImage); contrast(outputImage,atof(argv[i+1])); } else if ( strcmp(argv[i],"--sattest")==0 ) { float * tmp = allocateGaussianKernel(3,5.0,1); if (tmp!=0) { free(tmp); } tmp = allocateGaussianKernel(9,5.0,1); if (tmp!=0) { free(tmp); } tmp = allocateGaussianKernel(15,5.0,1); if (tmp!=0) { free(tmp); } summedAreaTableTest(); unsigned int * integralImageOutput = 0; integralImageOutput = generateSummedAreaTableRGB(inputImage->pixels , inputImage->width , inputImage->height); if (integralImageOutput!=0) { free(integralImageOutput); fprintf(stderr,"integralImage test was successful\n"); } } } writeImageFile(outputImage,outputType ,filenameOutput); destroyImage(outputImage); destroyImage(inputImage); return 1; } return 0; }
void LiquidCrystalDogC::begin(uint8_t cols, uint8_t rows, uint8_t mode) { uint8_t bias; _numcols = cols; _numrows = rows; if (rows > 1) { _displayfunction |= LCD_2LINE; } else { _displayfunction &= ~LCD_2LINE; } if (mode & LCD_DOG33V) { _dogpower = LCD_DOGBOOSTON; bias = LCD_DOGBIASLOW; } else { _dogpower = LCD_DOGBOOSTOFF; bias = LCD_DOGBIASHIGH; } // for some 1 line displays you can select a 10 pixel high font if ((mode & LCD_5x10DOTS) && (rows == 1)) { _displayfunction |= LCD_5x10DOTS; } else { _displayfunction &= ~LCD_5x10DOTS; } // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION! // according to datasheet, we need at least 40ms after power rises above 2.7V // before sending commands. Arduino can turn on way befer 4.5V so we'll wait 50 delayMicroseconds(50000); //we don't know which mode the LCD is in. maybe in the middle of a 4 bit mode transfer. force 8 bit mode. for(int i = 0; i < 3; i++) { // we start in 8bit mode, try to set 8 bit mode writebits(LCD_FUNCTIONSET | LCD_8BITMODE, LOW); delayMicroseconds(5000); // wait min 4.1ms } //put the LCD into 4 bit or 8 bit mode if (! (_displayfunction & LCD_8BITMODE)) { // finally, set to 4-bit interface writebits(LCD_FUNCTIONSET, LOW); delayMicroseconds(100); // commands and writes need > 37us to settle } if (mode & LCD_TYPEDOG) { _displaytype = LCD_TYPEDOG; command(LCD_FUNCTIONSET | _displayfunction | LCD_DOGIS1); command(LCD_DOGBIAS | bias | (rows == 3)); // bias command(LCD_DOGFOLLOW | 0x02); // follower control contrast(36, 1); } else { _displaytype = LCD_TYPESTD; } // finally, set # rows, font size, etc. command(LCD_FUNCTIONSET | _displayfunction); delay(5); // turn the display on with no cursor or blinking default _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF; display(); // clear it off clear(); // Initialize to default text direction (for romance languages) _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDISABLE; // set the entry mode command(LCD_ENTRYMODESET | _displaymode); }