ImFusion SDK 4.3
SimilarityMeasureFactory Class Reference

#include <ImFusion/Reg/SimilarityMeasureFactory.h>

The SimilarityMeasureFactory class provides a generic interface to any kind of SimilarityMeasure. More...

+ Inheritance diagram for SimilarityMeasureFactory:

Detailed Description

The SimilarityMeasureFactory class provides a generic interface to any kind of SimilarityMeasure.

Different types of SimilarityMeasures, with one or multiple implementations, can be registered to the factory during runtime. A set of default SimilarityMeasures are always registered.

Because different SimilarityMeasure may have different parameters, SimilarityMeasureFactory offers a generic way to access this parameters with the help of the ImFusion::Properties interface. Each SimilarityMeasureFactory contains a persistent Properties instance that contains the parameters of the current mode. This way, the Properties of a SimilarityMeasure can be accessed and modified without creating an actual instance of the SimilarityMeasure. Together with the ImFusion::PropertiesWidget it is relatively simple to generate a generic user interface to configure any kind of SimilarityMeasure.

Because some SimilarityMeasures use large amounts of (V)RAM for opimizations, a SimilarityMeasure instance should only be created while needed and deleted afterwards.

Basic usage:

SimilarityMeasureFactory factory;
SimilarityMeasureImpl* sm = factory.generate(img1, img2);
while(something) {
...
double val = sm->compute(nullptr);
...
}
delete sm;
SimilarityMeasureImpl * generate(SharedImage *img1, SharedImage *img2)
Generates a new SimilarityMeasure instance.
Base class of a similarity measure between two images.
Definition SimilarityMeasureBase.h:37
virtual double compute(const ImageTransformer *t, size_t *overlap=nullptr)=0
Computes and returns the similarity measure.

Exposing SimilarityMeasure properties in UI:

SimilarityMeasureFactory factory;
// show available modes in a combobox
for(auto mode: sm->availableModes())
qcombobox->addItem(QString::fromStdString(sm->acronym(mode)), (int)mode);
// create another combobox for available devices, connect signals...
...
// create a properties widget and show the current properties
PropertiesWidget pw;
Properties p("");
pw->configure(&p);
...
// get the user input from the widget and apply it to the factory
Properties p("");
pw->configuration(&p);
Storage container for serialization of arbitrary types, internally backed by strings.
Definition Properties.h:50
void configureSimilarityMeasure(const Properties *p)
Sets the configuration for the current SimilarityMeasure mode.
Mode mode() const
Returns the current SimilarityMeasure mode that the factory will generate.
void similarityMeasureConfiguration(Properties *p, bool filterUnrelated=true) const
Retrieves the configuration for a SimilarityMeasure of the current mode.

,

Public Types

enum  Mode : int {
  SAD = 0 , SSD = 1 , NCC = 2 , LNCC = 3 ,
  LC2 = 4 , MI = 5 , HIST = 6 , ML = 7 ,
  NGF = 8 , SSIM = 9 , DP = 10 , USERDEFINED = 100
}
 Enumeration of available similarity measures.
 

Public Member Functions

 SimilarityMeasureFactory (Mode mode=Mode::NCC, Device device=Device_GL)
 
std::vector< ModeavailableModes () const
 Returns all available modes of SimilarityMeasures in this factory.
 
std::vector< DeviceavailableDevices (Mode mode) const
 Returns all available implementations for a given mode.
 
std::string name (Mode mode) const
 Returns the full name of the SimilarityMeasure with the given mode.
 
std::string acronym (Mode mode) const
 Returns the acronym of the SimilarityMeasure with the given mode.
 
Mode mode () const
 Returns the current SimilarityMeasure mode that the factory will generate.
 
Device device () const
 Returns the current device for the mode generated by the factory.
 
void setMode (Mode mode)
 Sets the SimilarityMeasure mode the factory will generate If the current device is not available for this mode, the device will be changed to the first supported for this mode.
 
bool setDevice (Device device)
 Sets the device for the mode generated by the factory.
 
virtual void setWeights (const SharedImage *weights1, const SharedImage *weights2)
 Sets the images to use as weights for the similarity metric.
 
void configure (const Properties *p) override
 Configure this object instance by de-serializing the given Properties.
 
void configuration (Properties *p) const override
 Serialize the current object configuration into the given Properties object.
 
void similarityMeasureConfiguration (Properties *p, bool filterUnrelated=true) const
 Retrieves the configuration for a SimilarityMeasure of the current mode.
 
void configureSimilarityMeasure (const Properties *p)
 Sets the configuration for the current SimilarityMeasure mode.
 
template<typename T>
void setSimilarityMeasureParam (const std::string &name, const T &value)
 Convenient method to directly set a parameter of the SimilarityMeasure.
 
template<typename T>
bool similarityMeasureParam (const std::string &name, T &value)
 Convenient method to directly retrieve a parameter of the SimilarityMeasure.
 
SimilarityMeasureImplgenerate (SharedImage *img1, SharedImage *img2)
 Generates a new SimilarityMeasure instance.
 
- Public Member Functions inherited from FactoryBase
 FactoryBase ()
 No license check is performed for the module instantiated with this constructor.
 
 FactoryBase (std::string module, bool checkLicense=true)
 
std::string moduleName () const
 Returns the module name of the factory.
 
- Public Member Functions inherited from Configurable
virtual void configureDefaults ()
 Retrieve the properties of this object, replaces values with their defaults and sets it again.
 
void registerParameter (ParameterBase *param)
 Register the given Parameter or SubProperty, so that it will be configured during configure()/configuration().
 
void unregisterParameter (const ParameterBase *param)
 Remove the given Parameter or SubProperty from the list of registered parameters.
 
 Configurable (const Configurable &rhs)
 
 Configurable (Configurable &&rhs) noexcept
 
Configurableoperator= (const Configurable &)
 
Configurableoperator= (Configurable &&) noexcept
 

Static Public Member Functions

template<class T>
static bool registerSimilarityMeasure (Mode mode, Device device, const std::string &name, const std::string &acronym, std::function< SimilarityMeasureImpl *(SharedImage *, SharedImage *)> createFunc=nullptr)
 Registers a new SimilarityMeasure to the factory.
 
static void unregisterSimilarityMeasure (Mode mode, Device device)
 Removes a previous registered similarity measure.
 

Additional Inherited Members

- Public Attributes inherited from Configurable
Signal signalParametersChanged
 Emitted whenever one of the registered Parameters' or SubPropertys' signalValueChanged signal was emitted.
 
- Protected Member Functions inherited from FactoryBase
virtual ~FactoryBase ()
 Virtual destructor.
 
std::string getComponentPath (const std::string &componentName) const
 Returns the path to the component referred to by name.
 
bool isLicensed (const std::string &name)
 Return true if the license allows the use of the component referred to by name.
 
- Static Protected Member Functions inherited from FactoryBase
static std::string getComponentPath (const std::string &moduleName, const std::string &componentName)
 Returns the path to the component referred to by name.
 
static bool isLicensed (const std::string &moduleName, const std::string &name)
 Return true if the license allows the use of the component referred to by name.
 
- Protected Attributes inherited from FactoryBase
std::string m_factoryModule
 
bool m_checkLicense
 
- Protected Attributes inherited from Configurable
std::vector< Paramm_params
 List of all registered Parameter and SubProperty instances.
 

Member Function Documentation

◆ registerSimilarityMeasure()

template<class T>
static bool registerSimilarityMeasure ( Mode mode,
Device device,
const std::string & name,
const std::string & acronym,
std::function< SimilarityMeasureImpl *(SharedImage *, SharedImage *)> createFunc = nullptr )
inlinestatic

Registers a new SimilarityMeasure to the factory.

The template parameter must derive from ImFusion::SimilarityMeasureImpl. When registering multiple implementations for the same mode, the same name and acronym can be used. Example:

// register SAD with two different implementation
SimilarityMeasureFactory::registerSimilarityMeasure<SimilarityMeasureSAD_CPU>(SimilarityMeasureFactory::SAD, Device_CPU, "Sum of Absolute
Differences", "SAD"); SimilarityMeasureFactory::registerSimilarityMeasure<SimilarityMeasureSAD_GL>(SimilarityMeasureFactory::SAD,
Device_GL, "Sum of Absolute Differences", "SAD");
// register SSD with one implementation
SimilarityMeasureFactory::registerSimilarityMeasure<SimilarityMeasureSSD_CPU>(SimilarityMeasureFactory::SSD, Device_CPU, "Sum of Squared
Differences", "SSD");
static bool registerSimilarityMeasure(Mode mode, Device device, const std::string &name, const std::string &acronym, std::function< SimilarityMeasureImpl *(SharedImage *, SharedImage *)> createFunc=nullptr)
Registers a new SimilarityMeasure to the factory.
Definition SimilarityMeasureFactory.h:94

◆ setDevice()

bool setDevice ( Device device)

Sets the device for the mode generated by the factory.

If the given device is not supported by the current mode, the current device remains unchanged and false is returned.

◆ setWeights()

virtual void setWeights ( const SharedImage * weights1,
const SharedImage * weights2 )
virtual

Sets the images to use as weights for the similarity metric.

Setting weights only has effect if the similarity measure supports weights.

◆ configure()

void configure ( const Properties * p)
overridevirtual

Configure this object instance by de-serializing the given Properties.

The default implementation will do so automatically for all registered Parameter and SubProperty instances.

See also
configuration() for the inverse functionality

Reimplemented from Configurable.

◆ configuration()

void configuration ( Properties * p) const
overridevirtual

Serialize the current object configuration into the given Properties object.

The default implementation will do so automatically for all registered Parameter and SubProperty instances.

See also
configure() for the inverse functionality

Reimplemented from Configurable.

◆ similarityMeasureConfiguration()

void similarityMeasureConfiguration ( Properties * p,
bool filterUnrelated = true ) const

Retrieves the configuration for a SimilarityMeasure of the current mode.

If filterUnrelated is true, p will only contain parameters of the current SimilarityMeasure mode. Otherwise it may also contain parameters previous selected modes (which won't affect the SimilarityMeasure).

◆ configureSimilarityMeasure()

void configureSimilarityMeasure ( const Properties * p)

Sets the configuration for the current SimilarityMeasure mode.

The parameters are copied to the Properties instance of the factory, i.e. existing parameters will be overridden, all others stay unmodified.

◆ setSimilarityMeasureParam()

template<typename T>
void setSimilarityMeasureParam ( const std::string & name,
const T & value )

Convenient method to directly set a parameter of the SimilarityMeasure.

E.g. to set the 'patchSize' parameter of the LC2 SimilarityMeasure to 5:

SimilarityMeasureFactory factory;
factory.setMode(SimilarityMeasureFactory::LC2);
factory.setSimilarityMeasureParam("patchSize", 5);
void setMode(Mode mode)
Sets the SimilarityMeasure mode the factory will generate If the current device is not available for ...
void setSimilarityMeasureParam(const std::string &name, const T &value)
Convenient method to directly set a parameter of the SimilarityMeasure.
Definition SimilarityMeasureFactory.h:262

◆ similarityMeasureParam()

template<typename T>
bool similarityMeasureParam ( const std::string & name,
T & value )

Convenient method to directly retrieve a parameter of the SimilarityMeasure.

Returns true if the parameter exists.

◆ generate()

SimilarityMeasureImpl * generate ( SharedImage * img1,
SharedImage * img2 )

Generates a new SimilarityMeasure instance.

The actual instance created depends on the current mode and device of the factory. The instance is automatically configured with the current SimilarityMeasure properties of the factory. Once generated the SimilarityMeasure instance will be completely independent of the factory, e.g. any changes to the factory's mode, device or properties will NOT affect the instance. The caller is responsible for deleting the instance.


The documentation for this class was generated from the following file:
Search Tab / S to search, Esc to close