//--------------------------------------------------------- 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 ); }
//--------------------------------------------------------- bool CViGrA_Morphology::On_Execute(void) { bool bRescale; int Type, Radius; double Rank; CSG_Grid *pInput, *pOutput, Rescaled; pInput = Parameters("INPUT") ->asGrid(); pOutput = Parameters("OUTPUT") ->asGrid(); Type = Parameters("TYPE") ->asInt(); Radius = Parameters("RADIUS") ->asInt(); Rank = Parameters("RANK") ->asDouble(); bRescale = Parameters("RESCALE") ->asBool(); //----------------------------------------------------- if( bRescale ) { Rescaled.Create(*Get_System(), SG_DATATYPE_Byte); for(sLong i=0; i<Get_NCells() && Set_Progress_NCells(i); i++) { Rescaled.Set_Value(i, 0.5 + (pInput->asDouble(i) - pInput->Get_ZMin()) * 255.0 / pInput->Get_ZRange()); } pInput = &Rescaled; } //----------------------------------------------------- vigra::BImage Input, Output(Get_NX(), Get_NY()); Copy_Grid_SAGA_to_VIGRA(*pInput, Input, true); switch( Type ) { case 0: // Dilation discDilation (srcImageRange(Input), destImage(Output), Radius); break; case 1: // Erosion discErosion (srcImageRange(Input), destImage(Output), Radius); break; case 2: // Median discMedian (srcImageRange(Input), destImage(Output), Radius); break; case 3: // User defined rank discRankOrderFilter (srcImageRange(Input), destImage(Output), Radius, Rank); break; } //----------------------------------------------------- Copy_Grid_VIGRA_to_SAGA(*pOutput, Output, false); pOutput->Set_Name(CSG_String::Format(SG_T("%s [%s]"), pInput->Get_Name(), Get_Name().c_str())); return( true ); }