//---------------------------------------------------------
bool CViGrA_Watershed::On_Execute(void)
{
	CSG_Grid	*pInput  = Parameters("INPUT" )->asGrid();
	CSG_Grid	*pOutput = Parameters("OUTPUT")->asGrid();

	//-----------------------------------------------------
	if( !Parameters("RGB")->asBool() )
	{
		vigra::FImage	Input, Output(Get_NX(), Get_NY());

		Copy_Grid_SAGA_to_VIGRA(*pInput, Input, true);

		Segmentation(Input, Output, Parameters("SCALE")->asDouble(), Parameters("EDGES")->asBool());

		Copy_Grid_VIGRA_to_SAGA(*pOutput, Output, false);
	}

	//-----------------------------------------------------
	else	// perform watershed segmentation on color image
	{
		vigra::BRGBImage	Input, Output(Get_NX(), Get_NY());

		Copy_RGBGrid_SAGA_to_VIGRA(*pInput, Input, true);

		Segmentation(Input, Output, Parameters("SCALE")->asDouble(), Parameters("EDGES")->asBool());

		Copy_RGBGrid_VIGRA_to_SAGA(*pOutput, Output, false);
	}

	//-----------------------------------------------------
	pOutput->Fmt_Name("%s [%s]", pInput->Get_Name(), Get_Name().c_str());

	return( true );
}
Example #2
0
FireflyOptimizator::FireflyOptimizator( QString imagePath,  QString imageXml, float threshold, int MaxGenerations, int PopulationSize, float gamma)
: MaxGenerations(MaxGenerations), PopulationSize(PopulationSize), imagePath(imagePath) , imageXml(imageXml), gamma(gamma),threshold(threshold)
{
    SegmentedImage im2("/Users/zulli/Documents/city/sun_abnjbjjzwfckjhyx.jpg","/Users/zulli/Documents/city/sun_abnjbjjzwfckjhyx.xml");

    listaCor = vector<Vec3b*>(0);
    groundTruth = Segmentation(im2,threshold,listaCor);

    //regions = *groundTruth.getRegions();

    init();
}
Example #3
0
void CToolCervicales::Segmentation(CDib * m_Dib, CRxDoc * i_Document, POSITION c_Pos, POSITION l_Pos, CList<CPoint, CPoint&>& i_List, int Iteration, CList<CPoint, CPoint&>& Result) {
	if ((!c_Pos) || (!l_Pos) || (c_Pos == l_Pos)) return;
	POSITION first_Position = c_Pos;
	POSITION last_Position = l_Pos;
	CPoint l_FirstPoint = i_List.GetNext(c_Pos);
	CPoint l_LastPoint = i_List.GetNext(l_Pos);
	/* plot first and last points */
	m_Dib->PutPixel(l_FirstPoint.x, l_FirstPoint.y, (COLORREF) 255);
	m_Dib->PutPixel(l_LastPoint.x, l_LastPoint.y, (COLORREF) 255);
	/* find the maximum error point */
	CPoint l_MaxPoint = l_FirstPoint, l_Point;
	double l_Distance, max_Distance = -1;
	POSITION max_Position = NULL, p_Pos;
	while (c_Pos != NULL) {
		p_Pos = c_Pos;
		l_Point = i_List.GetNext(c_Pos);
		l_Distance = CAVector::Distance(l_FirstPoint, l_LastPoint, l_Point);
		if (l_Distance > max_Distance) {
			l_MaxPoint = l_Point;
			max_Distance = l_Distance;
			max_Position = p_Pos;
		}
		//m_Dib->PutPixel(l_Point.x, l_Point.y, 0);
	}
	if (max_Distance > 1) m_Dib->PutPixel(l_MaxPoint.x, l_MaxPoint.y, (COLORREF) 255);
	else return;
	/*
	CAVector FirstVector; FirstVector.Add(l_FirstPoint); FirstVector.Add(l_MaxPoint); FirstVector.Add(l_LastPoint);
	i_Document->Add(FirstVector);
	*/
	if (Iteration >= 4) {
		return;
	} else if (max_Distance > 0) {
		if ((l_MaxPoint != l_FirstPoint)&&(l_MaxPoint != l_LastPoint)) {
			Segmentation(m_Dib, i_Document, first_Position, max_Position, i_List, Iteration+1, Result);
			Result.AddTail(l_MaxPoint);
			Segmentation(m_Dib, i_Document, max_Position, last_Position, i_List, Iteration+1, Result);
		}
	}
}
Example #4
0
void FireflyOptimizator::updateGeneration()
{
    vector<Segmentation>::iterator ffI;
    int idx_ffI =0;

    for( ffI = population.begin(),idx_ffI=0; ffI != population.end(); idx_ffI++,ffI++)
    {

        *ffI = Segmentation(imagePath,markers[idx_ffI],threshold,listaCor);//ranks[idx_ffI] =  ranker.evaluate(&ffI->getRegions(),&regions);


    }
}
Example #5
0
void CFoosballDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
	char command[32];
	long NewPos;

	if (nSBCode == TB_THUMBTRACK) {
		NewPos = nPos;
	}
	else if (nSBCode == TB_PAGEUP || nSBCode == TB_PAGEDOWN) {
		NewPos = ((CSliderCtrl *)pScrollBar)->GetPos();
	}
	else
		return;

	if (pScrollBar == (CScrollBar*)&m_SliderMove) {
		m_DragMove = TRUE;
		sprintf_s(command, "%d", NewPos);
		SetDlgItemText(IDC_STATIC_MOVE, CA2W(command));
		sprintf_s(command, "!G %d %d\r", MOVE_MOTOR, NewPos);
		Device[DeviceMap[m_PositionSelection]].Write(command);
	}
	else if (pScrollBar == (CScrollBar*)&m_SliderPlayer && NewPos != SC.PlayerThreshold) {
		sprintf_s(command, "%d", NewPos);
		SC.PlayerThreshold = NewPos;
		SetDlgItemText(IDC_STATIC_PLAYER, CA2W(command));
		Segmentation();
		DisplayImage(BinBuf, TRUE);
	}
	else if (pScrollBar == (CScrollBar*)&m_SliderBall && NewPos != SC.BallThreshold) {
		sprintf_s(command, "%d", NewPos);
		SC.BallThreshold = NewPos;
		SetDlgItemText(IDC_STATIC_BALL, CA2W(command));
		Segmentation();
		DisplayImage(BinBuf, TRUE);
	}

	__super::OnHScroll(nSBCode, nPos, pScrollBar);
}
Example #6
0
CAVector CToolCervicales::SegmentationGlob(CDib * m_Dib, CRxDoc * i_Document, CList<CPoint, CPoint&>& i_List) {
	CList<CPoint, CPoint&> Result;
	
	Result.AddTail(i_List.GetHead());
	Segmentation(m_Dib, i_Document, i_List.GetHeadPosition(), i_List.GetTailPosition(), i_List, 0, Result);
	Result.AddTail(i_List.GetTail());

	CAVector Vector; CPoint l_Point;
	POSITION c_Pos = Result.GetHeadPosition();
	while (c_Pos != NULL) {
		l_Point = Result.GetNext(c_Pos);
		Vector.Add(CPoint(l_Point.x, m_Dib->GetHeight()-l_Point.y));
	}
	/* replace very close points by an intermediate value */	
	for (int i=2;i<(int)((double)(m_Dib->GetWidth() + m_Dib->GetHeight())/2 * 0.03);i++) RemoveClosePoints(Vector, i);
	/* remove pattern points */
	RemovePatternPoints(Vector);
	//i_Document->Add(Vector);
	return Vector;
}
Example #7
0
void SpinScan(uint8_t* rawData, int init)
{
	RAW_DATA raw_x;
	static int counter = 0;
	static int sx, sy, sz, posx, posy, posz, vx, vy, vz;
	if (init == 0)
	{
		raw_x.raw_data = 0;

		raw_x.data_byte[0] = rawData[0];	
		raw_x.data_byte[1] = rawData[1];
		if ((rawData[1] & 0x80) == 0x00)																							// Input data is positive, set the sign to 0
		{
			raw_x.data_byte[2] = 0;
			raw_x.data_byte[3] = 0;
		}
		else																																					// Input data is negative, set the sign to 1
		{
			raw_x.data_byte[2] = 0xFF;
			raw_x.data_byte[3] = 0xFF;
		}
		
		counter++;
		velocityX(raw_x.raw_data, &vx, 0);
		if ( (counter & 0x1) != 0 || counter >= 125)
		{
			PositionX(vx, &posx, 0);
			//f6 << posx << std::endl;
			Segmentation(posx);
		}
	}
	else
	{
		counter = 0;
	}
}