Ejemplo n.º 1
0
//---------------------------------------------------------------------------
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;
}
const std::vector<std::vector<int> > ribi::FilterOperationerMainDialog::PixmapToVector(const QPixmap& pixmap)
{
  return ImageToVector(pixmap.toImage());
}
Ejemplo n.º 3
0
Archivo: art.c Proyecto: cran/PET
/****************************************************************************
[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;
}