unibas-gravis / scalismo-faces

Scalable Image Analysis and Shape Modelling: Module to work with 2d images, with a focus on face images
Apache License 2.0
118 stars 27 forks source link

Draw a random coefficient sample in MoMoInstance #94

Closed andreas-schneider closed 6 years ago

andreas-schneider commented 6 years ago

Currently, it is laborious to draw a random MoMoInstance random coefficient that can be used for example rendering a random model sample.

Functionality: Draws shape, color and expression vector entries N(0,1) distributed.

This is a possible use case of the proposed functionality:

val model: MoMo = ???
val renderer = MoMoRenderer(model)
val parameter = RenderParameter.defaultSquare.withMoMo(MoMoInstance.sample(model))
val randomRendering = renderer.renderImage(parameter)
BernhardEgger commented 6 years ago

In this implementation the coefficients are always of full rank of the model. In practice it is often desired to have only the first x parameters. The MoMo itself has already a sample function which gives the VertexColorMesh directly. Without the possibility to use less parameters I see no benefit...

andreas-schneider commented 6 years ago

@Andreas-Forster I have incorporated your suggestions.

@BernhardEgger

sschoenborn commented 6 years ago

Just a side note: In PancakeDLRGP you have a coefficientsDistribution - this could be a possible concept to capture the distribution (including a sample() method) of the coefficients for a model

Andreas-Forster commented 6 years ago

@sschoenborn Thank you for pointing that out. I think this is maybe the best solution for this. I provided the implementation in addition to the former one.

@BernhardEgger I think it is a rare case where you want to have coefficients with a lot of different length in one application. So given this new solution, you would truncate the model first before sampling the coefficients. This makes also the generation of instances faster afterward.

@andreas-schneider It would now be possible to write:

  val model: MoMo = ???
  val modelURI: URI = ???
  val renderer = MoMoRenderer(model)
  val parameter = RenderParameter.defaultSquare.withMoMo(MoMoInstance.fromCoefficients(model.sampleCoefficients(),modelURI))
  val randomRendering = renderer.renderImage(parameter)

What do you think about this solution?

(Please do not merge as we should clean one of the solutions before.)

andreas-schneider commented 6 years ago

Yes, the sampleCoefficients sounds good. I have updated it accordingly.