예제 #1
0
void Fluid::ComputePressureField(
    int maxIterations,
    const View<float, 1>& velocitiesDivergence,
    View<float, 1>* pressureField) const {
  const float alpha = -_gridScale * _gridScale;
  const float beta = 4.0f;
  // TODO: What would be a meaningfull initial guess?
  FillImage(0.0f, pressureField);
  FillBorders(1.0f, velocitiesDivergence, pressureField);
  _pressureSolver.Solve(alpha, beta, maxIterations, velocitiesDivergence, pressureField);
}
예제 #2
0
void CImageProcess::ZoomImage(IplImage *in, IplImage *out)
{
	CvSize size;
	size.width = 14;
	size.height = 14;
	IplImage*	pZoom = cvCreateImage(size, in->depth, in->nChannels);
	memset(pZoom->imageData, 0 ,pZoom->imageSize);
	cvResize(in, pZoom, CV_INTER_AREA);

	FillImage(pZoom, out);
	cvReleaseImage(&pZoom);
}
예제 #3
0
void Fluid::Diffuse(
    float timeStep,
    int maxIterations,
    const View2f& velocities,
    View2f* velocitiesDiffused) const {
  const float alpha = (_gridScale * _gridScale) / (_viscosity * timeStep);
  const float beta = 4.0f + alpha;
  // TODO: What would be a meaningfull initial guess ?
  FillImage(Vector2(0.0f, 0.0f), velocitiesDiffused);
  FillBorders(-1.0f, velocities, velocitiesDiffused);
  _diffusionSolver.Solve(alpha, beta, maxIterations, velocities, velocitiesDiffused);
}
예제 #4
0
파일: Taiji.c 프로젝트: yoyao/C
 int main(int arvc,int* argv[])
 {
     struct MyImage* p_img =CreatImage(800,800);
     if(p_img != NULL)
     {
         printf("not null\n");
     }
 
     FillImage(p_img,0xaa);//最大为全白 最小为全黑
     DrawImage(p_img,300);
     SaveImage(p_img,"../bagua.pgm");
     DestoryImage(p_img);
 
 
 
 
     return 1;
 }
예제 #5
0
void CImageProcess::ZoomImage_16(vector<IplImage*> *source, vector<IplImage*> *out)
{
	vector<IplImage*>::iterator it = source->begin();
	for(; it != source->end(); it++){
		CvSize size;
		size.height = 16;
		size.width =16;
		IplImage *image = cvCreateImage(size, (*it)->depth, (*it)->nChannels);
		memset(image->imageData, 255, image->imageSize);

		size.width = 14;
		size.height = 10;
		IplImage*	pZoom = cvCreateImage(size, (*it)->depth, (*it)->nChannels);
		memset(pZoom->imageData, 255 ,pZoom->imageSize);
		cvResize(*it, pZoom, CV_INTER_LINEAR);

		FillImage(pZoom, image);
		cvReleaseImage(&pZoom);
		out->push_back(image);

	}
}
예제 #6
0
static void
ResampleMask (Image &Mask,                                  // out
              const Image &Src,                             // in
              int nNewWidth, int nNewHeight, double Scale)  // in
{
Image TempImg(nNewWidth, nNewHeight);
byte  *buf = TempImg.buf;

FillImage(TempImg, 255);

for (int iy = 0; iy < nNewHeight; iy++)     // scan over lower resolution image
    for (int ix = 0; ix < nNewWidth; ix++)
        {
        int ix1 = int(0.5 + ix / Scale);
        if (ix1 >= Src.width)
            ix1 = Src.width-1;
        int iy1 = int(0.5 + iy / Scale);
        if (iy1 >= Src.height)
            iy1 = Src.height-1;
        int ix2 = int(0.5 + (ix + 1) / Scale);
        if (ix2 >= Src.width)
            ix2 = Src.width-1;
        int iy2 = int(0.5 + (iy + 1) / Scale);
        if (iy2 >= Src.height)
            iy2 = Src.height-1;
        int i, j;
        for (j = iy1; j <= iy2; j++)    // scan over corresponding pixels in hi res
            for (i = ix1; i <= ix2; i++)
                if (!Src(i,j))
                    {                   // if any pixel is zero, make new pixel zero
                    *buf = 0;
                    goto next;
                    }
        next:
            buf++;
        }
Mask = TempImg;
}
예제 #7
0
void CImageProcess::ZoomImage(vector<Image> *in, vector<Image> *out, Location &zoo)
{
	for(int i=0; i<in->size(); i++){
		char c[10];
		itoa(i+10, c, 10);

		Image zootmp;
		zootmp._width = zoo._start - 2;
		zootmp._height = zoo._end - 2;
		zootmp._pData = new unsigned char[zootmp._width * zootmp._height];
		memset(zootmp._pData, 0, zootmp._width * zootmp._height);
		ZoomImage(in->at(i), zootmp);
		
		Image dsttmp;
		dsttmp._width = zoo._start;
		dsttmp._height = zoo._end;
		dsttmp._pData = new unsigned char[dsttmp._width * dsttmp._height];
		FillImage(zootmp, dsttmp);
		delete []zootmp._pData;
		out->push_back(dsttmp);
		IplImage *img = CreateImage(dsttmp, c);
	}
}
예제 #8
0
/* ----------------------------- MNI Header -----------------------------------
@NAME       : main
@INPUT      : 
@OUTPUT     : none
@RETURNS    : none
@DESCRIPTION: Sets up a new MINC file so that it can contain image data.
              Creates the dimensions, and the image, time, time-width,
              image-max, and image-min variables.
@METHOD     : none
@GLOBALS    : ncopts
@CALLS      : GetArgs
              CreateDims
              MINC library
              NetCDF library
@CREATED    : June 3, 1993 by MW
@MODIFIED   : 
---------------------------------------------------------------------------- */
int main (int argc, char *argv[])
{
   char   *TimeStamp;           /* to be put in the history attribute */
   nc_type NCType;
   Boolean Signed;

   long    NumFrames;           /* lengths of the various image dimensions */
   long    NumSlices;
   long    Height;
   long    Width;

   int     ChildCDF;
   int     ParentCDF;

   /* NumDim will be the number of image dimensions actually created in
    * the MINC file; DimIDs and DimNames will hold the ID's and names
    * of these dimensions.  There will be 2 dimensions if both NumFrames
    * and NumSlices are zero; 3 dimensions if either one but not both is
    * zero; and 4 dimensions if neither are zero.  (Height and Width must
    * always be non-zero.)
    */

   int     NumDim;       
   int     DimIDs [MAX_IMAGE_DIM];
   char   *DimNames [MAX_IMAGE_DIM];

   int	   NumExclude;
   int	   Exclude[MAX_NC_DIMS];


   ErrMsg = (char *) calloc (256, sizeof (char));
   TimeStamp = time_stamp (argc, argv);
   GetArgs (&argc, argv,
            &NumFrames, &NumSlices, &Height, &Width, 
            &NCType, &Signed);

#ifdef DEBUG
   printf ("main: Parent file: %s; new file: %s\n\n", gParentFile, gChildFile);
#endif

   ncopts = 0;

   ERROR_CHECK 
      (OpenFiles (gParentFile, gChildFile, &ParentCDF, &ChildCDF));

   ERROR_CHECK 
      (CreateDims (ChildCDF, NumFrames, NumSlices, Height, Width, 
		   gOrientation, &NumDim, DimIDs, DimNames));
   ERROR_CHECK
      (CreateDimVars (ParentCDF, ChildCDF, NumDim, DimIDs, DimNames, 
		      &NumExclude, Exclude));

   ERROR_CHECK 
      (CreateImageVars (ChildCDF, NumDim, DimIDs, NCType, Signed, gValidRange));

#ifdef DEBUG
   printf ("--------------------------------------------------------------\n");
   printf ("State of %s immediately before entering CopyOthers:\n",gParentFile);
   DumpInfo (ParentCDF);

   printf ("--------------------------------------------------------------\n");
   printf ("State of %s immediately before entering CopyOthers:\n", gChildFile);
   DumpInfo (ChildCDF);
#endif


   /*
    * Now, copy everything else of possible interest from the parent file
    * (but only if it exists!) to the child file.
    */

   if (ParentCDF != -1)
   {
      FinishExclusionLists (ParentCDF, NumDim, DimNames, &NumExclude, Exclude);

      ERROR_CHECK
	 (CopyOthers (ParentCDF, ChildCDF, NumExclude, Exclude, TimeStamp));
   }

   if (gImageVal != DBL_MAX)
      ERROR_CHECK (FillImage (ChildCDF, NumDim, DimIDs, gImageVal));

   ncclose (ChildCDF);
   if (ParentCDF != -1)
   {
      ncclose (ParentCDF);
   }
   return (0);

}
예제 #9
0
void Fluid::Fill(float xfill, float yfill) {
  Vector2 fillxy(xfill, yfill);
  FillImage(fillxy, &_velocities->View());
}
예제 #10
0
int main(int argc, char* argv[])
{
  // Verify arguments
  if(argc < 5)
  {
    std::cout << "Usage: PatchImage repeatX repeatY outputImage" << std::endl;
    return EXIT_FAILURE;
  }

  // Parse arguments
  std::string patchImageFilename = argv[1];

  std::stringstream ssRepeatX;
  ssRepeatX << argv[2];
  unsigned int repeatX = 0;
  ssRepeatX >> repeatX;

  std::stringstream ssRepeatY;
  ssRepeatY << argv[3];
  unsigned int repeatY = 0;
  ssRepeatY >> repeatY;

  std::string outputFilename = argv[4];

  // Output arguments
  std::cout << "Patch image: " << patchImageFilename << std::endl
            << "Repeat X: " << repeatX << std::endl
            << "Repeat Y: " << repeatY << std::endl
            << "Output image: " << outputFilename << std::endl;

  //typedef itk::VectorImage<float, 2> ImageType;
  typedef itk::Image<itk::CovariantVector<float, 3>, 2> ImageType;

  // Read patch image
  typedef itk::ImageFileReader<ImageType> ImageReaderType;
  ImageReaderType::Pointer patchImageReader = ImageReaderType::New();
  patchImageReader->SetFileName(patchImageFilename);
  patchImageReader->Update();

  Mask::Pointer mask = Mask::New();
  itk::ImageRegion<2> patchRegion = patchImageReader->GetOutput()->GetLargestPossibleRegion();
  mask->SetRegions(patchRegion);
  mask->Allocate();

  itk::Index<2> holeCorner = {{1,1}};
  itk::Size<2> holeSize = patchRegion.GetSize();
  holeSize[0] -= 2; // Missing one row on the top, and one row on the bottom
  holeSize[1] -= 2; // Missing one column on the left, and one column on the right
  itk::ImageRegion<2> holeRegion(holeCorner, holeSize);
  mask->SetValid(patchRegion);
  mask->SetHole(holeRegion);


  ImageType::Pointer seamlessPatch = ImageType::New();
  ITKHelpers::DeepCopy(patchImageReader->GetOutput(), seamlessPatch.GetPointer());

  // Enforce periodic boundary conditions
  // Top and bottom
  for(int i = 0; i < static_cast<int>(patchRegion.GetSize()[1]); ++i)
  {
      itk::Index<2> topPixelIndex = {{0, i}};
      itk::Index<2> bottomPixelIndex = {{static_cast<int>(patchRegion.GetSize()[0])-1, i}};
      ImageType::PixelType topPixelValue = seamlessPatch->GetPixel(topPixelIndex);
      ImageType::PixelType bottomPixelValue = seamlessPatch->GetPixel(bottomPixelIndex);
      ImageType::PixelType averageValue = (topPixelValue + bottomPixelValue)/2.0f;
      seamlessPatch->SetPixel(topPixelIndex, averageValue);
      seamlessPatch->SetPixel(bottomPixelIndex, averageValue);
  }

  // Left and right
  for(int i = 0; i < static_cast<int>(patchRegion.GetSize()[0]); ++i)
  {
      itk::Index<2> leftPixelIndex = {{i, 0}};
      itk::Index<2> rightPixelIndex = {{i, static_cast<int>(patchRegion.GetSize()[1])-1}};
      ImageType::PixelType leftPixelValue = seamlessPatch->GetPixel(leftPixelIndex);
      ImageType::PixelType rightPixelValue = seamlessPatch->GetPixel(rightPixelIndex);
      ImageType::PixelType averageValue = (leftPixelValue + rightPixelValue)/2.0f;
      seamlessPatch->SetPixel(leftPixelIndex, averageValue);
      seamlessPatch->SetPixel(rightPixelIndex, averageValue);
  }

  typedef PoissonEditingParent::GuidanceFieldType GuidanceFieldType;

  std::vector<GuidanceFieldType::Pointer> guidanceFields = PoissonEditingParent::ComputeGuidanceField(patchImageReader->GetOutput());

  ImageType::Pointer output = ImageType::New();

  FillImage(seamlessPatch.GetPointer(), mask.GetPointer(),
            guidanceFields, output.GetPointer(),
            patchRegion, seamlessPatch.GetPointer());


  // Write output
  ITKHelpers::WriteRGBImage(output.GetPointer(), outputFilename);

  // Original tiled
  ImageType::Pointer originalTiled = ImageType::New();
  TilePatch(patchImageReader->GetOutput(), repeatX, repeatY, originalTiled.GetPointer());
  ITKHelpers::WriteRGBImage(originalTiled.GetPointer(), "original_tiled.png");

  // Seamless tiled
  ImageType::Pointer seamlessTiled = ImageType::New();
  TilePatch(output.GetPointer(), repeatX, repeatY, seamlessTiled.GetPointer());
  ITKHelpers::WriteRGBImage(seamlessTiled.GetPointer(), "seamless_tiled.png");

  return EXIT_SUCCESS;
}