コード例 #1
0
/// It seems that blur[par.Scales+1] is compared in two succesive iterations
void OctaveKeypoints(flimage & image, float octSize, keypointslist& keys,siftPar &par)
{
	// Guoshen Yu, 2010.09.21, Windows version
   // flimage blur[par.Scales+3], dogs[par.Scales+2];
	int size_blur = par.Scales+3;
	int size_dogs = par.Scales+2;	  
    flimage *blur = new flimage[size_blur];
	flimage *dogs = new flimage[size_dogs];

 	float sigmaRatio = (float) pow(2.0, 1.0 / (double) par.Scales);


	/* Build array, blur, holding par.Scales+3 blurred versions of the image. */
	blur[0] = flimage(image);	/* First level is input to this routine. */ 
	float prevSigma = par.InitSigma;	/* Input image has par.InitSigma smoothing. */


	/* Form each level by adding incremental blur from previous level.
	Increase in blur is from prevSigma to prevSigma * sigmaRatio, so
	increase^2 = (prevSigma * sigmaRatio)^2 - prevSigma^2 
 	*/
	for (int i = 1; i < par.Scales + 3; i++) {

		if (DEBUG) printf("Convolving scale: %d \n", i);

		blur[i] = flimage(blur[i-1]);

		float increase = prevSigma*(float)sqrt((double)(sigmaRatio*sigmaRatio-1.0));

		gaussian_convolution( blur[i].getPlane(), blur[i].getPlane(), blur[i].nwidth(), blur[i].nheight(), increase);

		prevSigma *= sigmaRatio;

	}
	

	/* Compute an array, dogs, of difference-of-Gaussian images by
	subtracting each image from its next blurred version. */
	for (int i = 0; i < par.Scales + 2; i++) {

		dogs[i] = flimage(blur[i]);

		/// dogs[i] = dogs[i] - blur[i+1]
		combine(dogs[i].getPlane(),1.0f, blur[i+1].getPlane(),-1.0f, dogs[i].getPlane(),  dogs[i].nwidth() * dogs[i].nheight()); 
	}


	// Image with exact blur to be subsampled is blur[scales]
	image = blur[par.Scales];

	/* Scale-space extrema detection in this octave	*/
	if (DEBUG) printf("Looking for local maxima \n");

	FindMaxMin(dogs, blur, octSize, keys,par);
	
	// Guoshen Yu, 2010.09.22, Windows version
    delete [] blur;
	delete [] dogs;
}
コード例 #2
0
ファイル: demo_lib_sift.cpp プロジェクト: jguinet/s2p
/// It seems that blur[par.Scales+1] is compared in two succesive iterations
void OctaveKeypoints(flimage & image, float octSize, keypointslist& keys,siftPar &par)
{
	flimage* blur = new flimage[3];
	flimage* dogs = new flimage[3];
 	float sigmaRatio = (float) pow(2.0, 1.0 / (double) par.Scales);

	blur[0] = image; // First level is input to this routine
	float prevSigma = par.InitSigma; // Input image has par.InitSigma smoothing

    for(int i=1; i < 3; i++)
        blur[i] = alloc_image<float>(image.w, image.h);
    for(int i=0; i < 3; i++)
        dogs[i] = alloc_image<float>(image.w, image.h);
    
    int iDog = 0;
    for(int i=1; i < par.Scales+3; i++) {
		if (DEBUG) printf("Convolving scale: %d \n", i);
        if(i > 2)
            permute(blur);
        int j = (i==1)? 1: 2;
		float sigma = prevSigma*sqrt(sigmaRatio*sigmaRatio-1.0f);
		gaussian_convolution(blur[j-1].data, blur[j].data, blur[j].w, blur[j].h,
                             sigma);
		prevSigma *= sigmaRatio;
        
		/// dogs[i] = dogs[i] - blur[i+1]
		combine(blur[j-1].data,1.0f, blur[j].data,-1.0f,
                dogs[iDog].data, dogs[iDog].w*dogs[iDog].h); 
        if(iDog < 2)
            ++iDog;
        else {
            if (DEBUG) printf("************************scale: %d\n", i-2);
            FindMaxMin(dogs, blur[0], i-2, octSize, keys,par);
            permute(dogs);
        }
    }

    std::swap(image.data,blur[0].data);

    for(int i=1; i < 3; i++)
        free(blur[i].data);
    for(int i=0; i < 3; i++)
        free(dogs[i].data);
	delete [] blur;
	delete [] dogs;
}
コード例 #3
0
ファイル: WTiffIO.cpp プロジェクト: dyycy/IR_GPU_VS13
void WTiffIO::SaveFloatAsTiff(char* filename, int width, int height,float *img,  int sign)
{//
	unsigned short* image;
	image=new unsigned short[width*height];
	memset(image,0,width*height*sizeof(unsigned short));
	float Max,Min;
	FindMaxMin(img,width*height,&Max,&Min);
	switch(sign)
	{
	case 0:
		{//最大最小映射到灰度范围
			for(int i=0;i<height;i++)
			{
				for(int j=0;j<width;j++)
				{
					image[i*width+j]=(unsigned short)((img[i*width+j]-Min)*GRAY_LEVEL/(Max-Min));
				//	TRACE("image[i*width+j]=%d",image[i*width+j]);
				}
			}
			break;
		}	
	case 1:
		{//放弃了小于零的那部分数据
			for(int i=0;i<height;i++)
			{
				for(int j=0;j<width;j++)
				{
					if(img[i*width+j]<0)
						img[i*width+j]=0;
					image[i*width+j]=(unsigned short)((img[i*width+j])*GRAY_LEVEL/(Max-Min));
				}
			}
			break;
		}
	default:
		{
			cout<<"Bad  sign in SaveFloatAsTiff"<<endl;
			break;
		}
	}

	int realwidth=1,realheight=1;
	SaveTiff(filename,image,width,height,realwidth,realheight);
	delete image;

}
コード例 #4
0
ファイル: key.c プロジェクト: BOTSlab/bupimo_src
/* Find keypoints within one octave of scale space starting with the
   given image.  The octSize parameter gives the size of each pixel
   relative to the input image.  Returns new list of keypoints after
   adding to the existing list "keys".
*/
KKeypoint OctaveKeypoints(Image image, Image *pnextImage, float octSize,
			 KKeypoint keys)
{
    int i;
    float sigmaRatio, prevSigma, increase;
    Image blur[Scales+3], dogs[Scales+2];
 
    /* Ratio of each scale to the previous one.  The parameter Scales
       determines how many scales we divide the octave into, so
          sigmaRatio ** Scales = 2.0.  
    */
    sigmaRatio = pow(2.0, 1.0 / (float) Scales);

    /* Build array "blur", holding Scales+3 blurred versions of the image. */
    blur[0] = image;          /* First level is input to this routine. */
    prevSigma = InitSigma;    /* Input image has InitSigma smoothing. */

    /* Form each level by adding incremental blur from previous level.
       Increase in blur is from prevSigma to prevSigma * sigmaRatio, so
       increase**2 + prevSigma**2 = (prevSigma * sigmaRatio)**2
    */
    for (i = 1; i < Scales + 3; i++) {
      blur[i] = CopyImage(blur[i-1], IMAGE_POOL);
      increase = prevSigma * sqrt(sigmaRatio * sigmaRatio - 1.0);
      GaussianBlur(blur[i], increase);
      prevSigma *= sigmaRatio;
    }

    /* Compute an array, dogs, of difference-of-Gaussian images by
       subtracting each image from its next blurred version.
    */
    for (i = 0; i < Scales + 2; i++) {
      dogs[i] = CopyImage(blur[i], IMAGE_POOL);
      SubtractImage(dogs[i], blur[i+1]);
    }

    /* Image blur[Scales] has twice the blur of starting image for
       this octave, so it is returned to downsample for next octave.
    */
    *pnextImage = blur[Scales];

    return FindMaxMin(dogs, blur, octSize, keys);
}
コード例 #5
0
ファイル: WTiffIO.cpp プロジェクト: dyycy/IR_GPU_VS13
void WTiffIO::SaveFloatAsBmp(char* filename, int width, int height, float *img)
{//
	unsigned char* image;
	image=new unsigned char[width*height];
	memset(image,0,width*height*sizeof(unsigned char));
	float Max,Min;
	FindMaxMin(img,width*height,&Max,&Min);
	//最大最小映射到灰度范围
		for(int i=0;i<height;i++)
		{
			for(int j=0;j<width;j++)
			{
				image[i*width+j]=(unsigned char)((img[i*width+j]-Min)*255/(Max-Min));
			//	TRACE("image[i*width+j]=%d",image[i*width+j]);
			}
		}	
	SaveBitmap(filename,width,height,image);
	delete image;

}
void Deringing_Chroma(
    uint8 *Rec_C,
    int width,
    int height,
    int16 *QP_store,
    int Combined,
    uint8 *pp_mod
)
{
    OSCL_UNUSED_ARG(Combined);
    /*----------------------------------------------------------------------------
    ; Define all local variables
    ----------------------------------------------------------------------------*/
    int thres;
    int v_blk, h_blk;
    int max_diff;
    int v_pel, h_pel;
    int max_blk, min_blk;
    int v0, h0;
    uint8 *ptr;
    int sum, sum1, incr;
    int32 addr_v;
    int sign_v[10], sum_v[10];
    int *ptr2, *ptr3;
    uint8 pelu, pelc, pell;
    incr = width - BLKSIZE;

    /*----------------------------------------------------------------------------
    ; Function body here
    ----------------------------------------------------------------------------*/
    /* chrominance */
    /* Do the first line (7 pixels at a time => Don't use MMX)*/
    for (h_blk = 0;h_blk < width;h_blk += BLKSIZE)
    {
        max_diff = (QP_store[h_blk>>3] >> 2) + 4;
        ptr = &Rec_C[h_blk];
        max_blk = min_blk = *ptr;
        FindMaxMin(ptr, &min_blk, &max_blk, width);
        h0 = ((h_blk - 1) >= 1) ? (h_blk - 1) : 1;

        if (max_blk - min_blk >= 4)
        {
            thres = (max_blk + min_blk + 1) >> 1;


            for (v_pel = 1;v_pel < BLKSIZE - 1;v_pel++)
            {
                addr_v = (int32)v_pel * width;
                ptr = &Rec_C[addr_v + h0 - 1];
                ptr2 = &sum_v[0];
                ptr3 = &sign_v[0];

                pelu = *(ptr - width);
                pelc = *ptr;
                pell = *(ptr + width);
                ptr++;
                *ptr2++ = pelu + (pelc << 1) + pell;
                *ptr3++ = INDEX(pelu, thres) + INDEX(pelc, thres) + INDEX(pell, thres);

                pelu = *(ptr - width);
                pelc = *ptr;
                pell = *(ptr + width);
                ptr++;
                *ptr2++ = pelu + (pelc << 1) + pell;
                *ptr3++ = INDEX(pelu, thres) + INDEX(pelc, thres) + INDEX(pell, thres);

                for (h_pel = h0;h_pel < h_blk + BLKSIZE - 1;h_pel++)
                {
                    pelu = *(ptr - width);
                    pelc = *ptr;
                    pell = *(ptr + width);

                    *ptr2 = pelu + (pelc << 1) + pell;
                    *ptr3 = INDEX(pelu, thres) + INDEX(pelc, thres) + INDEX(pell, thres);

                    sum1 = *(ptr3 - 2) + *(ptr3 - 1) + *ptr3;
                    if (sum1 == 0 || sum1 == 9)
                    {
                        sum = (*(ptr2 - 2) + (*(ptr2 - 1) << 1) + *ptr2 + 8) >> 4;

                        ptr--;
                        if (PV_ABS(*ptr - sum) > max_diff)
                        {
                            if (sum > *ptr)
                                sum = *ptr + max_diff;
                            else
                                sum = *ptr - max_diff;
                        }
                        *ptr++ = (uint8) sum;
                    }
                    ptr++;
                    ptr2++;
                    ptr3++;
                }
            }
        }
コード例 #7
0
//This is the basic framework of a study function.
SCSFExport scsf_MyES_2ndEntriesSystem(SCStudyGraphRef sc)
{
	SCSubgraphRef LongSignal    = sc.Subgraph[0];
	SCSubgraphRef ShortSignal   = sc.Subgraph[1];
    
    SCSubgraphRef Long1stEntry  = sc.Subgraph[2];
    SCSubgraphRef Short1stEntry = sc.Subgraph[3];
		
    SCSubgraphRef AuxSignal = sc.Subgraph[4];
	//SCSubgraphRef MainMA    = sc.Subgraph[5];
	
	SCSubgraphRef FastFilter = sc.Subgraph[6];
	SCSubgraphRef SlowFilter = sc.Subgraph[7];
    	
	int& longEntryState  = sc.PersistVars->i1;
	int& shortEntryState = sc.PersistVars->i2;
	
	int& lastEntryBar   = sc.PersistVars->i3;
	int& longsEnable  = sc.PersistVars->i4;
	int& shortsEnable = sc.PersistVars->i5;
	
	SCInputRef length    = sc.Input[0];
	SCInputRef enabled   = sc.Input[1];
    
	float highest, lowest;
	
	// Section 1 - Set the configuration variables and defaults
	if (sc.SetDefaults)
	{
		sc.GraphName = "My ES 2nd Entries System";
		
		// During development set this flag to 1, so the DLL can be rebuilt without restarting Sierra Chart. When development is completed, set it to 0 to improve performance.
		sc.FreeDLL = 1;

		sc.AutoLoop = 1;  //Auto looping is enabled. 
		sc.GraphRegion = 0;
		
		//MainMA.Name = "Main MA";
		//MainMA.DrawStyle = DRAWSTYLE_LINE;
		//MainMA.AutoColoring = AUTOCOLOR_SLOPE;
		//MainMA.PrimaryColor = COLOR_BLUE;
		//MainMA.SecondaryColor = COLOR_MAGENTA;
		//MainMA.LineWidth = 2;
		
		LongSignal.Name = "Long Signal";
		LongSignal.DrawStyle = DRAWSTYLE_ARROWUP;
		LongSignal.PrimaryColor = COLOR_AQUAMARINE;
		LongSignal.LineWidth = 2;
		LongSignal.DrawZeros = false;
		
		ShortSignal.Name = "Short Signal";
		ShortSignal.DrawStyle = DRAWSTYLE_ARROWDOWN;
		ShortSignal.PrimaryColor = COLOR_MAGENTA;
		ShortSignal.LineWidth = 2;
		ShortSignal.DrawZeros = false;
        
        Long1stEntry.Name = "Long 1st Entry";
		Long1stEntry.DrawStyle = DRAWSTYLE_TRIANGLEUP;
		Long1stEntry.PrimaryColor = COLOR_AQUAMARINE;
		Long1stEntry.LineWidth = 2;
		Long1stEntry.DrawZeros = false;
        
        Short1stEntry.Name = "Short 1st Entry";
		Short1stEntry.DrawStyle = DRAWSTYLE_TRIANGLEDOWN;
		Short1stEntry.PrimaryColor = COLOR_MAGENTA;
		Short1stEntry.LineWidth = 2;
		Short1stEntry.DrawZeros = false;
		
		AuxSignal.Name = "Aux Signal";
		AuxSignal.DrawStyle = DRAWSTYLE_DIAMOND;
		AuxSignal.PrimaryColor = COLOR_YELLOW;
		AuxSignal.LineWidth = 2;
		AuxSignal.DrawZeros = false;
		
		sc.Input[0].Name = "Count Length";
		sc.Input[0].SetInt(55);
		
		enabled.Name = "Enable Trading";
		enabled.SetYesNo(0); 
        		
		longEntryState   = eStateInitial;
		shortEntryState  = eStateInitial;
		
		
		sc.AllowMultipleEntriesInSameDirection = false; 
		sc.MaximumPositionAllowed = 1;
		sc.SupportReversals = 0;
		
		// ** This false by default. Orders will go to the simulation system always. **
		// @@
		sc.SendOrdersToTradeService = true;
			
		sc.AllowOppositeEntryWithOpposingPositionOrOrders = false;
		
		sc.SupportAttachedOrdersForTrading = true;
		// ** this line will causes to not work
		//sc.TradeWindowConfigFileName = "1Contract.twconfig";
		
		sc.CancelAllOrdersOnEntriesAndReversals= true;
		sc.AllowEntryWithWorkingOrders = false;
		sc.CancelAllWorkingOrdersOnExit = false;
		
		// This is true by default, only 1 trade can be processed per bar.
		sc.AllowOnlyOneTradePerBar = true; 
		sc.MaintainTradeStatisticsAndTradesData = true;
		
		longsEnable  = 0;
		shortsEnable = 0;
		
		return;
	}
	
	// Setup buttons
	if (sc.MenuEventID != 0)
	{
		if(sc.MenuEventID == SC_ACS_TOOL1)
		{
			if(sc.MouseEventType == SC_ACS_TOOL_ON)
			{
				sc.AddMessageToLog("Longs On", 0);
				longsEnable = 1;
			}
			else if(sc.MouseEventType == SC_ACS_TOOL_OFF)
			{
				sc.AddMessageToLog("Longs Off", 0);
				longsEnable = 0;
			}
		}
		else if(sc.MenuEventID == SC_ACS_TOOL2)
		{
			if(sc.MouseEventType == SC_ACS_TOOL_ON)
			{
				sc.AddMessageToLog("Shorts On", 0);
				shortsEnable = 1;
			}
			else if(sc.MouseEventType == SC_ACS_TOOL_OFF)
			{
				sc.AddMessageToLog("Shorts Off", 0);
				shortsEnable = 0;
			}
		}
		else if(sc.MenuEventID == SC_ACS_TOOL3)
		{
			if(sc.MouseEventType == SC_ACS_TOOL_ON)
			{
				sc.AddMessageToLog("Pausing", 0);
				longsEnable = 0;
				shortsEnable = 0;
			}
		}
	}
	
	// Section 2 - Do data processing here

	//sc.ExponentialMovAvg(sc.Close, MainMA, length.GetInt());
	sc.WeightedMovingAverage(sc.BaseDataIn[SC_LAST], FastFilter, 20);
	sc.WeightedMovingAverage(sc.BaseDataIn[SC_LAST], SlowFilter, 35);
	
	FindMaxMin(sc, length.GetInt(), highest, lowest);
	
	if(sc.BaseData[SC_LAST][sc.Index] > highest ||
	   sc.BaseData[SC_HIGH][sc.Index] > highest)
	{
		longEntryState = eStateCount0;
		
		//@@
		//shortEntryState = eStateCount0;
	}

	if(sc.BaseData[SC_LAST][sc.Index] < lowest ||
	   sc.BaseData[SC_LOW][sc.Index]  < lowest)
	{
		shortEntryState = eStateCount0;
		
		//@@
		//longEntryState = eStateCount0;
	}

	
	switch(longEntryState)
	{
		case eStateCount0:

			if(sc.BaseData[SC_LAST][sc.Index] < sc.Low[sc.Index-1] ||
			   sc.BaseData[SC_LOW][sc.Index]  < sc.Low[sc.Index-1])           
			{
				longEntryState = eStateCount0Retrace;
			}
			break;
			
		case eStateCount0Retrace:
			
			if(sc.BaseData[SC_LAST][sc.Index] > sc.High[sc.Index-1] ||
			   sc.BaseData[SC_HIGH][sc.Index] > sc.High[sc.Index-1])
			{
				longEntryState = eStateCount1;
				
				// 1st entry
                Long1stEntry[sc.Index] = sc.Low[sc.Index]-sc.TickSize*2;
			}
			break;
			
		case eStateCount1:
			
			if(sc.BaseData[SC_LAST][sc.Index] < sc.Low[sc.Index-1] ||
			   sc.BaseData[SC_LOW][sc.Index]  < sc.Low[sc.Index-1]) 
			{
				longEntryState = eStateCount1Retrace;
			}
			break;
			
		case eStateCount1Retrace:

			if(sc.BaseData[SC_LAST][sc.Index] > sc.High[sc.Index-1] ||
			   sc.BaseData[SC_HIGH][sc.Index] > sc.High[sc.Index-1])
			{
				// 2nd entry
				LongSignal[sc.Index] = sc.Low[sc.Index]-sc.TickSize*2;
								
				longEntryState = eStateCount2;	
				
				if(longsEnable && enabled.GetYesNo() && FastFilter[sc.Index] > SlowFilter[sc.Index])
					EnterLongOrder(sc);
			}
			break;
			
		case eStateCount2:
			
			if(sc.BaseData[SC_LAST][sc.Index] < sc.Low[sc.Index-1] ||
			   sc.BaseData[SC_LOW][sc.Index]  < sc.Low[sc.Index-1] )
			{			
				longEntryState = eStateCount1Retrace;
			}
			break;
	}
	
	switch(shortEntryState)
	{
		case eStateCount0:

			if(sc.BaseData[SC_LAST][sc.Index] > sc.High[sc.Index-1] ||
			   sc.BaseData[SC_HIGH][sc.Index] > sc.High[sc.Index-1])           
			{
				shortEntryState = eStateCount0Retrace;
			}
			break;
			
		case eStateCount0Retrace:
			if(sc.BaseData[SC_LAST][sc.Index] < sc.Low[sc.Index-1] ||
			   sc.BaseData[SC_LOW][sc.Index]  < sc.Low[sc.Index-1])
			{
				shortEntryState = eStateCount1;
				
				// 1st entry
                Short1stEntry[sc.Index] = sc.High[sc.Index]+sc.TickSize*2;
			}
			break;
			
   		case eStateCount1:
   			if(sc.BaseData[SC_LAST][sc.Index] > sc.High[sc.Index-1] ||
			   sc.BaseData[SC_HIGH][sc.Index] > sc.High[sc.Index-1]) 
			{
				shortEntryState = eStateCount1Retrace;
			}
   			break;
   			
   		case eStateCount1Retrace:
   			if(sc.BaseData[SC_LAST][sc.Index] < sc.Low[sc.Index-1] ||
			   sc.BaseData[SC_LOW][sc.Index]  < sc.Low[sc.Index-1])
			{
				// 2nd entry
				ShortSignal[sc.Index] = sc.High[sc.Index]+sc.TickSize*2;
				
				shortEntryState = eStateCount2;	
				
				if(shortsEnable && enabled.GetYesNo() && FastFilter[sc.Index] < SlowFilter[sc.Index])
					EnterShortOrder(sc);
			}
   			break;
   			
   		case eStateCount2:
   			if(sc.BaseData[SC_LAST][sc.Index] > sc.High[sc.Index-1] ||
			   sc.BaseData[SC_HIGH][sc.Index] > sc.High[sc.Index-1] )
			{			
				//state5[sc.Index] = sc.Low[sc.Index]-sc.TickSize*11;
				shortEntryState = eStateCount1Retrace;
			}
   			break;
	}

	
	if(longEntryState == eStateCount1Retrace)
	{
		sprintf(arTempStr, "L arming");
	}
	else
	{
		sprintf(arTempStr, " ");
	}
	DrawText(sc, 9898, 4, 96, COLOR_GREEN, RGB(0,0,0), arTempStr);
	
	if(shortEntryState == eStateCount1Retrace)
	{
		sprintf(arTempStr, "S arming");
	}
	else
	{
		sprintf(arTempStr, " ");
	}
	DrawText(sc, 9899, 4, 92, COLOR_RED, RGB(0,0,0), arTempStr);
	
	if(enabled.GetYesNo() && longsEnable)
	{
		sprintf(arTempStr, "Long Enable");
		DrawText(sc, 9897, 4, 88, COLOR_GREEN, RGB(0,0,0), arTempStr);
	}
	else if(enabled.GetYesNo() && shortsEnable)
	{
		sprintf(arTempStr, "Short Enable");
		DrawText(sc, 9897, 4, 88, COLOR_RED, RGB(0,0,0), arTempStr);
	}
	else
	{
		sprintf(arTempStr, " ");
		DrawText(sc, 9897, 4, 88, COLOR_RED, RGB(0,0,0), arTempStr);
	}
	
}