예제 #1
0
///
/// \brief Vespucci::Math::Smoothing::MedianFilterMat
/// \param X
/// \param window_size
/// \return
/// Performs Median Filter over a arma::matrix with spectra in columns
arma::mat Vespucci::Math::Smoothing::MedianFilterMat(const arma::mat &X, arma::uword window_size)
{
    arma::mat filtered;
    filtered.set_size(X.n_rows, X.n_cols);   
    for(arma::uword i = 0; i < X.n_cols; ++i)
        filtered.col(i) = MedianFilter(X.col(i), window_size);
    return filtered;
}
예제 #2
0
void stereo_MedianFilter(void* inputFIFOs[], void* outputFIFOs[], Param inParams[], Param outParams[]){
	MedianFilter(
		/* height     */ (Param) inParams[2],
		/* width      */ (Param) inParams[0],
		/* sizeFilter */ (Param) inParams[1],
		/* in         */ (uint8_t*) inputFIFOs[0],
		/* out        */ (uint8_t*) outputFIFOs[0]
	);
}
예제 #3
0
void Document::medianFilter(uint radius)
{
    QImage orig = m_image.copy();

    QList<MedianFilter> jobs;
    for (int x = m_selection.x(); x <= m_selection.right(); ++x)
        jobs.append(MedianFilter(radius, orig, m_image, QPoint(x, m_selection.top()), m_selection.height()));

    QtConcurrent::blockingMap(jobs, MedianFilter::process);

    setModified(true);
    emit repaint(m_selection);
}
예제 #4
0
///
/// \brief Vespucci::Math::Smoothing::MedianFilterMat
/// \param X
/// \param window_size
/// \return
/// Performs Median Filter over a arma::matrix with spectra in columns
arma::mat Vespucci::Math::Smoothing::MedianFilterMat(const arma::mat &X, arma::uword window_size)
{
    arma::mat filtered;
    filtered.set_size(X.n_rows, X.n_cols);

#ifdef _WIN32
  #pragma omp parallel for default(none) \
      shared(X, window_size, filtered)
     for (intmax_t i = 0; i < (intmax_t) X.n_cols; ++i)
#else
  #pragma omp parallel for default(none) \
      shared(X, window_size, filtered)
    for (size_t i = 0; i < X.n_cols; ++i)
#endif
    {
        filtered.col(i) = MedianFilter(X.col(i), window_size);
    }

    return filtered;
}
void CLjz153View::OnMedianFilter() 
{
	// TODO: Add your command handler code here
	MedianFilter();
	Invalidate();
}
예제 #6
0
float SimpleFilter::WindowFilter(float* list, int windowSize) {
	float av = Average(MedianFilter(list, windowSize), 3);
	return av;
}
예제 #7
0
double FitCurve(TGraphErrors* g, int debug=0)
{
  
  double vdep=0;
  if(!g) return vdep;
  
  
  TF1* f3 = new TF1("fp1", "pol1", 20, 360);
  f3->SetLineColor(4);
  
  double y;
  double xlow=350;
  double ymax=0;
  double vdep1=0;
  // prendre le point le plus haut est robuste et marche bien pour les hauts vdep
  TGraphErrors *gsmooth = MedianFilter(g);
  gsmooth = MedianFilter(gsmooth);
  for(int ipt=0; ipt<gsmooth->GetN(); ipt++)
  {
    gsmooth->GetPoint(ipt, xlow, y);
	if(y>ymax) {ymax=y; vdep1=xlow;}
  }
  
  //g=gsmooth;
  int npt = g->GetN()-5;
  xlow=350;
  double chi2=0;
  int status = 0;
  while(chi2<5. && xlow>100 && npt>=0)
  {
    g->GetPoint(npt, xlow, y);
    f3->SetRange(xlow, 350);
    status = g->Fit("fp1", "rqn");
    chi2 = f3->GetChisquare()/f3->GetNDF();
    if(debug>=1) cout<<"xlow "<<xlow<<" chi2 "<<chi2<<endl;
	npt--;
  }
  g->GetPoint(npt+2, xlow, y);
  f3->SetRange(xlow, 350);
  g->Fit("fp1", "rqn");
  vdep = xlow;
  
  //if(vdep>230) vdep = vdep1;
  //else if(fabs(vdep-vdep1)>40) vdep = vdep1;
  //vdep=vdep1;

  cout<<" Vdepl = "<<vdep<<endl;
  
  
  
  TF1* f1 = new TF1("fitsigmo", fitsigmo, 50, 350, 5);
  f1->SetParameter(0, 3.);
  f1->SetParameter(1, 0.02);
  f1->SetParameter(2, vdep);
  f1->SetParameter(3, -10.);
  f1->SetParameter(4, -0.00001);
  f1->SetParLimits(2, 100., 300.);
  f1->SetParLimits(4, -0.1, 0);
  
  
  
  
  TF1* f2 = new TF1("fitpol", fitpol, 20, 360, 6);
  f2->SetParLimits(4, 100., 300.);
  f2->SetParLimits(5, -0.1, 0);
  
 /* xlow = 30;
  chi2 = 100;
  double xmin = xlow;
  double chi2min = chi2;
  string opt="rq";
  if(debug>=2) opt="r";
  while(chi2>0.1 && xlow<vdep-80)
  {
    f2->SetParameter(0, 1.);
    f2->SetParameter(1, 0.005);
    f2->SetParameter(2, 0.0001);
    f2->SetParameter(3, 0.);
    f2->SetParameter(4, vdep);
    f2->SetParameter(5, -0.00001);
    f2->SetRange(xlow, 350);
    status = g->Fit("fitpol", opt.c_str());
    if(status!=0) status = g->Fit("fitpol", opt.c_str());
    chi2 = f2->GetChisquare()/f2->GetNDF();
    if(debug>=1) cout<<"xlow "<<xlow<<" chi2 "<<chi2<<endl;
    if(debug>=2) cout<<" chi2 "<<f2->GetChisquare()<<" ndf "<<f2->GetNDF()<<endl;
	if(chi2<chi2min) {chi2min=chi2; xmin=xlow;}
	xlow+=10;
  }
  f2->SetParameter(0, 1.);
  f2->SetParameter(1, 0.005);
  f2->SetParameter(2, 0.0001);
  f2->SetParameter(3, 0.);
  f2->SetParameter(4, vdep);
  f2->SetParameter(5, -0.00001);
  f2->SetRange(xmin, 350);
  status = g->Fit("fitpol", opt.c_str());
  if(status!=0) status = g->Fit("fitpol", opt.c_str());
  vdep = f2->GetParameter(4);
  cout<<" Vdepl2 = "<<vdep<<" xmin "<<xmin<<endl;
  if(fabs(vdep-vdep1)>30) vdep = vdep1;
*/




      TGraphErrors* gmedian;
      gmedian = MedianFilter( g );
      int nfilt=1;
      /*while (!IsMonoton(gmedian) && nfilt<4) {
        gmedian = MedianFilter( gmedian );
        nfilt++;
      }*/
      gmedian = HanningFilter(gsmooth);
      cout<<nfilt<<" median filter applied"<<endl;

      TGraphErrors* gscurv = GetCurvatureGraph( gmedian );
      gscurv->SetMarkerStyle(20);
      TGraph* g3pts = new TGraph();
      float xopt = GetOptimalMinNPts(gscurv, g3pts);

      vdep = xopt;

      cout<<" Kink = "<<xopt<<endl;


  TCanvas *c1;
  TCanvas *c2;
  if(debug>=1)
  {
    c1 = new TCanvas();
    g->Draw("AP");
    f2->Draw("same");
    f3->Draw("same");
	//gsmooth->SetMarkerColor(17);
	//gsmooth->Draw("P");
//gmedian->SetMarkerColor(4);
//gmedian->Draw("P");	
	TLine *l = new TLine(vdep,2, vdep, ymax+0.1);
	l->SetLineStyle(3);
	l->Draw();
 
    c1->Modified();
    c1->Update();

    string detid = g->GetTitle();
    detid.erase(0,6);
    //c1->Print(Form("ClusterWidthVsVbias_detid_%s_run203832.eps", detid.c_str()));

    c2 = new TCanvas;
    gscurv->Draw("AP");
    g3pts->Draw("P");
    g3pts->Fit("pol2", "q");
    c2->Modified();
    c2->Update();

    //c2->Print(Form("ClusterWidthVsVbias_detid_%s_curv_run203832.eps", detid.c_str()));

    getchar();
    c1->Close();
    c2->Close();
  }

  return vdep;
}
예제 #8
0
 MedianFilter operator =(const MedianFilter& other) {
     return MedianFilter(other.m_radius, other.m_orig, other.m_image, other.m_start, other.m_height);
 }
void CStereoMatching::MatchOneLayer(cv::Mat disparity[], int Pyrm_depth)
{
	if (Verbose>=1)
		printf("\tprocessing layer %d...\n",Pyrm_depth);
	clock_t start = clock();
	cv::Mat image[2], mask[2];
	cv::Mat image_inv[2], mask_inv[2];
	image[0] = m_data->imagePyrm[Pyrm_depth][0];
	image[1] = m_data->imagePyrm[Pyrm_depth][1];
	mask[0]  = m_data->maskPyrm[Pyrm_depth][0];
	mask[1]  = m_data->maskPyrm[Pyrm_depth][1];
	image_inv[0] = image[1];
	image_inv[1] = image[0];
	mask_inv[0] = mask[1];
	mask_inv[1] = mask[0];
	FindMargin(margin[0], m_data->maskPyrm[Pyrm_depth][0]);
	FindMargin(margin[1], m_data->maskPyrm[Pyrm_depth][1]);
	if (Pyrm_depth == 0)
	{
		LowestLevelInitialMatch(image, mask, disparity[0], true);
		LowestLevelInitialMatch(image_inv, mask_inv, disparity[1], false);
	}
	else
	{
		HighLevelInitialMatch(image, mask, disparity[0], Pyrm_depth, true);
		HighLevelInitialMatch(image_inv, mask_inv, disparity[1], Pyrm_depth, false);
	}
// 	DisparityToCloud<short>(disparity[0], mask[0], Q, 0, true, 10);
// 	m_data->SaveMat(disparity[0], "disparity0.dat");
// 	m_data->SaveMat(disparity[1], "disparity01.dat");
	SmoothConstraint(disparity[0], true);
	SmoothConstraint(disparity[1], false);
//	DisparityToCloud<short>(disparity[0], mask[0], Q, 0, true, 11);
	//m_data->SaveMat(disparity[0], "disparity1.dat");
	//m_data->SaveMat(disparity[1], "disparity11.dat");
	OrderConstraint(disparity[0], true);
	OrderConstraint(disparity[1], false);
	//m_data->SaveMat(disparity[0], "disparity2.dat");
	//m_data->SaveMat(disparity[1], "disparity21.dat");
	UniquenessContraint<short>(disparity);
//m_data->SaveMat(disparity[0], "disparity3.dat");
//m_data->SaveMat(disparity[1], "disparity31.dat");
// 	MedianFilter(disparity[0], mask[0], 1, true);
// 	MedianFilter(disparity[1], mask[1], 1, false);
	Rematch(image, mask, disparity[0], true);
	Rematch(image_inv, mask_inv, disparity[1], false);
// 	SmoothConstraint(disparity[0], true);
// 	SmoothConstraint(disparity[1], false);
// 	OrderConstraint(disparity[0], true);
// 	OrderConstraint(disparity[1], false);
	UniquenessContraint<short>(disparity);
//m_data->SaveMat(disparity[0], "disparity4.dat");
//m_data->SaveMat(disparity[1], "disparity41.dat");
	MedianFilter(disparity[0], mask[0], 1, true);
	MedianFilter(disparity[1], mask[1], 1, false);
	
//  m_data->SaveMat(disparity[0], "disparity50.dat");
//  m_data->SaveMat(disparity[1], "disparity51.dat");
// 	DisparityToCloud<short>(disparity[0], mask[0], Q, Pyrm_depth, true, 11+10*Pyrm_depth);
	int iteration = 30+Pyrm_depth*30;
//	clock_t part = clock();
	DisparityRefine(disparity[0], image, iteration, true);
	DisparityRefine(disparity[1], image_inv, iteration, false);
//	printf("\ttime: %.3f s\n", double(clock()-part)/1e3);
// 	disparity[0].convertTo(disparity[0],CV_64FC1);
// 	disparity[1].convertTo(disparity[1],CV_64FC1);
//	m_data->SaveMat(disparity[0], "disparity6.dat");
//	m_data->SaveMat(disparity[1], "disparity61.dat");
// 	char filename[512];
// 	sprintf(filename, "disparity%d_0.dat", Pyrm_depth);
// 	m_data->SaveMat(disparity[0], filename);
// 	sprintf(filename, "disparity%d_1.dat", Pyrm_depth);
// 	m_data->SaveMat(disparity[1], filename);
	UniquenessContraint<double>(disparity);
	
// 	m_data->SaveMat(disparity[0], "disparity70.dat");
	printf("\ttime: %.3f s\n", double(clock()-start)/1e3);
}
예제 #10
0
void TOUCHSCR_Handler( void )
{
    static s32 divider_coord = 0;

    vs32 vX = 0;
    vs32 vY = 0;
    vs32 vT = 0;
    vs32 X, Y, T, q;

    tPOINT display, screen;

    // Don't execute, if it's not time
    if (( divider_coord++ % Max_cnt_ts ) != 0 )
        return;

    // Filtered values out of ADC_NB_SAMPLES samples
    vX = MedianFilter( ADC_ConvertedValue + OFS_CHANNEL_TS + 0 );
    vY = MedianFilter( ADC_ConvertedValue + OFS_CHANNEL_TS + 1 );
    vT = MedianFilter( ADC_ConvertedValue + OFS_CHANNEL_TS + 2 );

    // Conversion voltage => points
    q = ( 4096 - vY );
    X = ( 1000 *     vX ) / q;
    Y = ( 1000 * ( vY - vT ) ) / q;
    T = ( 1000 * ( vT - vX ) ) / q;

    // See if touch pressed
    TOUCHSCR_Info.TouchPress = ( vT < TS_Sensibility );
    if ( TOUCHSCR_Info.TouchPress )
    {
        TOUCHSCR_Info.xRaw = X;
        TOUCHSCR_Info.yRaw = Y;

        // Correction with calibration coefficients
        vX = (( TS_CalibrationSetup.A * X )
        + ( TS_CalibrationSetup.B * Y )
        + ( TS_CalibrationSetup.C ) )
        /   TS_CalibrationSetup.R;

        Y  = (( TS_CalibrationSetup.D * X )
        + ( TS_CalibrationSetup.E * Y )
        + ( TS_CalibrationSetup.F ) )
        /   TS_CalibrationSetup.R;

        X = vX;

        if ( X < 0 ) X = 0;
        if ( Y < 0 ) Y = 0;

        // Adapt coordinates versus screen position
        s32 x2 = 0, y2 = 0;
        switch ( LCD_GetScreenOrientation() )
        {
        case V12:
            x2 = X;
            y2 = Y;
            break;
        case V9:
            x2 = Screen_Height - Y;
            y2 = X;
            break;
        case V3:
            x2 = Y ;
            y2 = Screen_Width - X;
            break;
        case V6:
            x2 = ( Screen_Width - X );
            y2 = Screen_Height - Y;
            break;
        }

        // Update global structure for diffusion
        TOUCHSCR_Info.xAbsPos = X;
        TOUCHSCR_Info.yAbsPos = Y;
        TOUCHSCR_Info.xPos = x2 - LCD_Offset;
        TOUCHSCR_Info.yPos = y2 - LCD_Offset;

        // Reset stanby time-out
        POWER_Set_Time();
    }
    else
    {
        TOUCHSCR_Info.xRaw = -1;
        TOUCHSCR_Info.yRaw = -1;
        TOUCHSCR_Info.xAbsPos = -1;
        TOUCHSCR_Info.yAbsPos = -1;
        TOUCHSCR_Info.xPos = -1;
        TOUCHSCR_Info.yPos = -1;

    } // End if touchpress


    switch ( TOUCHSCR_Info.Mode )
    {
    case TS_CALIBRATION:
        TOUCHSCREEN_Calibration();
        break;
    case TS_DRAWING:
        if ( Y < Screen_Height )  // Discard buttons
            TOUCHSCREEN_Drawing();
        break;
    case TS_NORMAL:
    default:
        break;
    }

} // End of touchscreen handler