const QPixmap ribi::FilterOperationerMainDialog::DoFilterOperation( const QPixmap& source, const boost::numeric::ublas::matrix<double>& filter) { const std::vector<std::vector<int> > v { PixmapToVector(source) }; const std::vector<std::vector<double> > w { MatrixToVector(filter) }; const std::vector<std::vector<int> > x { DoFilterOperation( v, //y-x-ordered w //y-x-ordered ) }; const QImage image { VectorToImage(x) }; QPixmap result { QPixmap::fromImage(image) }; return result; }
//--------------------------------------------------------------------------- void __fastcall TFormMain::ButtonDoClick( TObject *Sender) { const std::vector<std::vector<int> > source_int = ImageToVector(ImageSource); const std::vector<std::vector<double> > source = Convert<int,double>(source_int); const std::vector<std::vector<double> > result_unscaled = DoFilterOperation(source,mFilter); const std::vector<std::vector<double> > result_scaled = Rescale(result_unscaled,0.0,255.9); const std::vector<std::vector<int> > result = Convert<double,int>(result_scaled); VectorToImage(result,ImageTarget); ImageTarget->Visible = true; ImageTarget->Refresh(); ButtonSaveResult->Enabled = true; ++PageControl->ActivePageIndex; }
/*************************************************************** [NAME] SaveIteration [SYNOPSIS] void SaveIteration(Vector *MyVector, int iteration, char *filename) [DESCRIPTION] This function is used to save a series of images while iterating. The function saves an image with the specified outputname + a number indicating which iteration the picture represents. [USAGE] {\tt SaveIteration(TestVector, 123, "testImage");} Saves the vector {\tt TestVector} as the image `{\tt testimage.123.pet}'. [REVISION] Dec. 94, JJJ July 2006, Joern Schulz ***************************************************************/ void SaveIteration(Vector *MyVector, int iteration, char *filename) { char outfilename[100]; char itstr[10]; Image *NewImage; strcpy(outfilename,filename); sprintf(itstr,".%d",iteration); strcat(outfilename,itstr); NewImage=VectorToImage(MyVector,itINI.XSamples,itINI.YSamples); RenameImage(NewImage,outfilename); NewImage->DeltaX=itINI.DeltaX; NewImage->DeltaY=itINI.DeltaY; NewImage->Xmin=itINI.Xmin; NewImage->Ymin=itINI.Ymin; ScaleImage(NewImage); WritePET(NewImage); FreeImage(NewImage); }
/**************************************************************************** [NAME] SLOW\_ART [SYNOPSIS] Image *SLOW_ART(Vector *xvector, Vector *bvector) [DESCRIPTION] This function will iterate towards a solution for the sparse system of equations \mb{b}=\mb{A x}, where \mb{b} is the sinogram (Radon domain) and \mb{x} is the reconstructed image to be found. The function uses a slow version of ART (Algebraric Reconstruction Techniques) where the transformation matrix is calculated on the fly. [USAGE] {\tt Image=ART(TestMatrix, TestSinogram);} Reconstructs the sinogram {\tt TestSinogram}, returns it as an image. [REVISION] Jan. 95, JJJ and PT July 06, J.Schulz, Modification of ReadRefImage and the condition to SaveIterions ****************************************************************************/ Image *SLOW_ART(Vector *xvector, Vector *bvector) { int ARows,ACols,currentrow,currentiteration,TotalIterations,AntPrint,UseRefImage; float denom,lambda,brk; //refxdev=0.0; float *tempXv,*tempBv; char DiffFileName[200]; FILE *DiffFile=NULL; Vector *refxvector=NULL,*AVector; Image *Recon,*RefImage=NULL; ARows=bvector->N; ACols=xvector->N; Print(_DNormal,"Using ART (slow) to solve %i equations with %i unknowns\n", ARows,ACols); UseRefImage=(strlen(itINI.RefFileName)!=0); if (UseRefImage!=0) { RefImage=ReadRefImage(itINI.RefFileName); refxvector=ImageToVector(RefImage); FreeImage(RefImage); //refxdev=DeviationVector(refxvector); strcpy(DiffFileName,itINI.RefFileName); strcat(DiffFileName,".dif"); DiffFile=fopen(DiffFileName,"wt"); Print(_DNormal,"Logging differences in `%s' \n", DiffFileName); } tempXv=xvector->value; tempBv=bvector->value; //srand((int)clock()); lambda=itINI.Alpha/itINI.Beta; TotalIterations=itINI.Iterations*ARows; AntPrint=(int)(TotalIterations/93); InitArrays(); for (currentiteration=0;currentiteration<TotalIterations;currentiteration++) { if (currentiteration%ARows==0) lambda*=itINI.Beta; if (currentiteration%AntPrint==0) Print(_DNormal,"Iterating %6.2f %% done\r", (currentiteration+1)*100.0/TotalIterations); if (itINI.IterationType==1) currentrow=currentiteration%ARows; else { //currentrow=(int)(ARows*(float)rand()/(RAND_MAX+1.0)); GetRNGstate(); currentrow = (int)(ARows*runif(0, 1)); //currentrow = (int)(ARows*runif(0, RAND_MAX)/(RAND_MAX+1.0)); PutRNGstate(); } AVector=GenerateAMatrixRow(currentrow); denom=MultVectorVector(AVector,AVector); if (fabs(denom)>1e-9) { brk=lambda*(tempBv[currentrow]-MultVectorVector(AVector,xvector))/denom; ARTUpdateAddVector2(xvector, AVector, brk); } FreeVector(AVector); if ( (itINI.SaveIterations) && (currentiteration != 0) && (!(currentiteration%(ARows*(itINI.SaveIterations)))) ) SaveIteration(xvector,(int)(currentiteration/ARows),itINI.SaveIterationsName); if (UseRefImage==1) if (currentiteration%AntPrint==0) fprintf(DiffFile,"%f %f\n",(double)currentiteration/ARows, (double)L2NormVector(refxvector,xvector)); /*fprintf(DiffFile,"%f %f\n",(double)currentiteration/ARows, (double)L2NormVector(refxvector,xvector,refxdev));*/ } Print(_DNormal," \r"); Recon=VectorToImage(xvector,itINI.XSamples,itINI.YSamples); if (UseRefImage==1){ Print(_DNormal,"L2 = %9.6f \n",L2NormVector(refxvector,xvector)); //Print(_DNormal,"L2 = %9.6f \n",L2NormVector(refxvector,xvector,refxdev)); FreeVector(refxvector); fclose(DiffFile); } RenameImage(Recon,"ReconstructedImage"); Recon->DeltaX=itINI.DeltaX; Recon->DeltaY=itINI.DeltaY; Recon->Xmin=itINI.Xmin; Recon->Ymin=itINI.Ymin; return Recon; }