ImageData ReadLUTFile(const char *lutfile) { PathSeperator sep(lutfile); if(sep.extension == "jpg") { return ReadJPEGFile(lutfile); } else { std::string fn = lutfile; fn = std::string(fn.begin(), fn.begin()+fn.find('#')); std::string num( ++( sep.extension.begin() + sep.extension.find('#') ), sep.extension.end()); int lutIndex = atoi(num.c_str()); int nbeads, nplanes, nsteps; FILE *f = fopen(fn.c_str(), "rb"); if (!f) throw std::runtime_error("Can't open " + fn); fread(&nbeads, 4, 1, f); fread(&nplanes, 4, 1, f); fread(&nsteps, 4, 1, f); fseek(f, 12 + 4* (nsteps*nplanes * lutIndex), SEEK_SET); ImageData lut = ImageData::alloc(nsteps,nplanes); fread(lut.data, 4, nsteps*nplanes,f); fclose(f); lut.normalize(); return lut; } }
int main(int argc, char** argv) { timer *tic, *toc; CImage *cimg=NULL; Image *mask=NULL; Histogram *hist=NULL; if (argc != 4) { fprintf(stderr,"usage: extrai_bic <image> <mask> <outputfile>\n"); exit(-1); } cimg = ReadJPEGFile(argv[1]); mask = ReadImage(argv[2]); tic = Tic(); hist = BIC(cimg, mask); toc = Toc(); printf("BIC extracted in %f milliseconds\n\n",CTime(tic, toc)); FILE *fp; fp = fopen(argv[3],"w"); if (fp == NULL) { fprintf(stderr,"Cannot open %s\n",argv[3]); exit(-1); } WriteFHist(hist, fp); DestroyCImage(&cimg); DestroyHistogram(&hist); DestroyImage(&mask); fclose(fp); return(0); }
void CorrectedRadialProfileTest() { // read image const char* imgname = "SingleBead.jpg"; ImageData img = ReadJPEGFile(imgname); // localize CPUTracker trk(img.w,img.h); trk.SetImageFloat(img.data); vector2f com = trk.ComputeMeanAndCOM(); bool boundaryHit; vector2f qi = trk.ComputeQI(com, 4, 64, 64,ANGSTEPF, 1, 30, boundaryHit); dbgprintf("%s: COM: %f, %f. QI: %f, %f\n", imgname, com.x, com.y, qi.x, qi.y); std::vector<float> angularProfile(128); float asym = trk.ComputeAsymmetry(qi, 64, angularProfile.size(), 1, 30, &angularProfile[0]); // ComputeAngularProfile(&angularProfile[0], 64, angularProfile.size(), 1, 30, qi, &img, trk.mean); WriteImageAsCSV("angprof.csv", &angularProfile[0], angularProfile.size(), 1); dbgprintf("Asymmetry value: %f\n", asym); std::vector<float> crp(128); float* crpmap = new float[angularProfile.size()*crp.size()]; ComputeCRP(&crp[0], crp.size(), angularProfile.size(), 1, 30, qi, &img, 0.0f); WriteImageAsCSV("crpmap.csv", crpmap, crp.size(), angularProfile.size()); delete[] crpmap; delete[] img.data; //CRP_TestGeneratedData(); // GenerateImageFromLUT(ImageData(img,w,h), ImageData }
// load jpeg file BOOL CJpeg::Load(LPCSTR lpstrFileName) { UINT uWidth, uHeight, uWidthDW; // read the jpeg to a packed buffer of RGB bytes BYTE *lpTmpBuffer = ReadJPEGFile(lpstrFileName, &uWidth, &uHeight); if (lpTmpBuffer == NULL) return FALSE; // do this before DWORD-alignment!!! // swap red and blue for display BGRFromRGB(lpTmpBuffer, uWidth, uHeight); // now DWORD-align for display BYTE *lpBuffer = MakeDwordAlign(lpTmpBuffer, uWidth, uHeight, &uWidthDW); FreeBuffer(lpTmpBuffer); // flip for display VertFlipBuf(lpBuffer, uWidthDW, uHeight); BITMAPINFOHEADER bmiHeader; bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bmiHeader.biWidth = uWidth; bmiHeader.biHeight = uHeight; bmiHeader.biPlanes = 1; bmiHeader.biBitCount = 24; bmiHeader.biCompression = BI_RGB; bmiHeader.biSizeImage = 0; bmiHeader.biXPelsPerMeter = 0; bmiHeader.biYPelsPerMeter = 0; bmiHeader.biClrUsed = 0; bmiHeader.biClrImportant = 0; // Allocate enough memory for the new CF_DIB, and copy bits DWORD dwHeaderSize = sizeof(BITMAPINFOHEADER); DWORD dwBitsSize = WIDTHBYTES(uWidth*24) * uHeight; HDIB hDIB = GlobalAlloc(GHND, dwHeaderSize + dwBitsSize); if (hDIB == NULL) return FALSE; LPBYTE lpDIB = (LPBYTE)GlobalLock(hDIB); memcpy(lpDIB, (LPBYTE)&bmiHeader, dwHeaderSize); memcpy(FindDIBBits((LPBYTE)lpDIB), lpBuffer, dwBitsSize); FreeBuffer(lpBuffer); if (m_pDib != NULL) delete m_pDib; m_pDib = new CDib(); m_pDib->Attach(hDIB); return TRUE; }
void CRP_TestGeneratedData() { int w=64,h=64; float* img = new float[w*h]; const char* lutname = "LUTexample25X.jpg"; std::vector<uchar> lutdata = ReadToByteBuffer(lutname); int lutw,luth; uchar* lut; ReadJPEGFile(&lutdata[0], lutdata.size(), &lut, &lutw, &luth); delete[] img; }
void AutoBeadFindTest() { auto img = ReadJPEGFile("00008153.jpg"); auto smp = ReadJPEGFile("00008153-s.jpg"); BeadFinder::Config cfg; cfg.img_distance = 0.5f; cfg.roi = 80; cfg.similarity = 0.5; auto results=BeadFinder::Find(&img, smp.data, &cfg); for (uint i=0;i<results.size();i++) { dbgprintf("beadpos: x=%d, y=%d\n", results[i].x, results[i].y); img.at(results[i].x+cfg.roi/2, results[i].y+cfg.roi/2) = 1.0f; } dbgprintf("%d beads total\n", results.size()); FloatToJPEGFile("autobeadfind.jpg", img.data, img.w, img.h); img.free(); smp.free(); }
ImageData ReadJPEGFile(const char*fn) { int w, h; uchar* imgdata; std::vector<uchar> jpgdata = ReadToByteBuffer(fn); ReadJPEGFile(&jpgdata[0], jpgdata.size(), &imgdata, &w,&h); float* fbuf = new float[w*h]; for (int x=0;x<w*h;x++) fbuf[x] = imgdata[x]/255.0f; delete[] imgdata; return ImageData(fbuf,w,h); }
void GenerateZLUTFittingCurve(const char *lutfile) { QTrkSettings settings; settings.width = settings.height = 80; QueuedCPUTracker qt(settings); ImageData lut = ReadJPEGFile(lutfile); ImageData nlut; ResampleLUT(&qt, &lut, lut.h, &nlut); CPUTracker trk(settings.width,settings.height); ImageData smp = ImageData::alloc(settings.width,settings.height); trk.SetRadialZLUT(nlut.data, nlut.h, nlut.w, 1, qt.cfg.zlut_minradius, qt.cfg.zlut_maxradius, false, false); int N=8; for (int z=0;z<6;z++) { vector3f pos(settings.width/2,settings.height/2, nlut.h * (1+z) / (float)N + 0.123f); GenerateImageFromLUT(&smp, &nlut, qt.cfg.zlut_minradius, qt.cfg.zlut_maxradius, pos); ApplyPoissonNoise(smp, 10000); WriteJPEGFile( SPrintf("zlutfitcurve-smpimg-z%d.jpg", z).c_str(), smp); trk.SetImageFloat(smp.data); std::vector<float> profile(qt.cfg.zlut_radialsteps), cmpProf(nlut.h), fitted(nlut.h); trk.ComputeRadialProfile(&profile[0], qt.cfg.zlut_radialsteps, qt.cfg.zlut_angularsteps, qt.cfg.zlut_minradius, qt.cfg.zlut_maxradius, pos.xy(), false); trk.LUTProfileCompare(&profile[0], 0, &cmpProf[0], CPUTracker::LUTProfMaxQuadraticFit, &fitted[0]); WriteArrayAsCSVRow("zlutfitcurve-profile.txt", &profile[0], profile.size(), z>0); WriteArrayAsCSVRow("zlutfitcurve-cmpprof.txt", &cmpProf[0], cmpProf.size(), z>0); WriteArrayAsCSVRow("zlutfitcurve-fitted.txt", &fitted[0], fitted.size(), z>0); } smp.free(); nlut.free(); lut.free(); }