GithubHelp home page GithubHelp logo

Configure Analyze Regions about morpholibj HOT 14 OPEN

ijpb avatar ijpb commented on July 17, 2024
Configure Analyze Regions

from morpholibj.

Comments (14)

dlegland avatar dlegland commented on July 17, 2024 1

I guess this does the trick?!

Yes! Works like classical methods from the Collections framework, but returns instance to "this".

Isn't that some kind of builder pattern?

To be honest, I do not really know... Returning an instance to this is typical from the Builder pattern, but the builder approaches I have seen often use two different classes: one for the builder, another one for the main class. Here, there is no "build()" method at the end.
Or maybe the MorphometricFeatures2D class can be seen as a builder for a ResultsTable!

from morpholibj.

dlegland avatar dlegland commented on July 17, 2024 1

Hi!
a small follow-up, I have just pushed the refactoring of the AnalyzeRegions3D plugin to use a new MorphometricFeatures3D based on the same principle that the 2D equivalent.

Everything seems to work fine: same behaviour as before, and it is now possible to choose features programmatically.
I am just not totally satisfied with management of options, but this will be for a future enhancement.

On the roadmap is also the refactoring of the dialogs for analysis of regions. This may take some time however.

from morpholibj.

dlegland avatar dlegland commented on July 17, 2024

Hi @tischi,
I do not think this is possible. When using an ImageJ plugin, one has to rely on the "run" method.
One way could be to split the implementation, such that the plugin class only manages the GUI. I plan to refactor the Analyze regions plugins in a near future, so maybe I can also add this feature, if it is possible and not too hard.

from morpholibj.

tischi avatar tischi commented on July 17, 2024

Thanks! A very easy fix would be to make the boolean variables public. What do you think?

from morpholibj.

dlegland avatar dlegland commented on July 17, 2024

Hi,
yes, you're right, this could be a quick fix! I try to have a look soon!

from morpholibj.

tischi avatar tischi commented on July 17, 2024

@dlegland any progress on this front? :-)

from morpholibj.

dlegland avatar dlegland commented on July 17, 2024

Hi,
not much at the moment,
but I plan to check this when I come back from holidays. hopefully end of august or beginning of september...

best,
David

from morpholibj.

dlegland avatar dlegland commented on July 17, 2024

Hi,
I just pushed a commit that updates the AnayzeRegions plugins.

It introduces an inner class "Features", that contains public boolean fields for selecting the features to compute. Example:

// creates a new Features instance to select the features to compute.  
AnalyzeRegions.Features features = new AnalyzeRegions.Features();
features.setAll(false);
features.area = true;
features.perimeter = true;
features.centroid = true;
    
// compute the features, and returns the corresponding table
ResultsTable table = AnalyzeRegions.process(imagePlus, features);
table.show("Morphometry");

Feedback welcome!

from morpholibj.

dlegland avatar dlegland commented on July 17, 2024

Proposition from @oburri: use a Builder type approach.

ResultsTable table = AnalyzeRegions.create( imagePlus )
       .getArea()
       .getPerimeter()
       .getCentroid()
       .compute();

from morpholibj.

lacan avatar lacan commented on July 17, 2024

In case you're interested in this kind of Builder Pattern refactoring, I'd be happy to help, as I do love MorphoLibJ

from morpholibj.

dlegland avatar dlegland commented on July 17, 2024

Hi @tischi and @lacan ,

I finally arrived at a new refactoring of the AnalyzeRegions class!

The main thing is that the computation part is now managed by the "MorphometricFeartures2D" class (within inra.ijpb.analyze.regions2d package). I was trying with builder type approach, but finally used a collection features (instances of the inner "Feature" enum). A typical call can be as follow:

ResultsTable table = new MorphometricFeatures2D()
    .add(Feature.AREA)
    .add(Feature.PERIMETER)
    .add(Feature.CENTROID)
    .computeTable(imagePlus);

An alternative with adequate static imports:

ResultsTable table = new MorphometricFeatures2D(AREA, PERIMETER, CENTROID)
    .computeTable(imagePlus);

The AnalyzeRegions have been updated to call the MorphometricFeatures2D class. The AnalyzeRegions.Features class have been deprecated, and the code was adapted to use the MorphometricFeatures2D class. It seems to work as previously.

I would lije to have a more generic approach, that would allow to add new user-defined features without having to change code in MorphoLibJ, but I could not yet find a simple enough solution...

from morpholibj.

tischi avatar tischi commented on July 17, 2024

@dlegland

  1. Thank you very much! Looks beautiful!
  2. What happens if one does this: ResultsTable table = new MorphometricFeatures2D().computeTable(imagePlus); does one get all or none?
  3. Will that also work in 3D with the same API?
  4. finally used a collection features (instances of the inner "Feature" enum). I am intrigued, could you post a link to the code?

from morpholibj.

dlegland avatar dlegland commented on July 17, 2024

Thank you very much! Looks beautiful!

Thank you! I hope this will be more scriptable than the AnalyzeRegions plugin, and that this will not be too complicated to maintain by introducing new features...

What happens if one does this: ResultsTable table = new MorphometricFeatures2D().computeTable(imagePlus); does one get all or none?

One get an empty table. Only the region label is provided.

Will that also work in 3D with the same API?

Yes! working on it... nearly ready, I just would like to enhance unit tests and general checks.

finally used a collection features (instances of the inner "Feature" enum). I am intrigued, could you post a link to the code?

Sure! the main class is MorphometricFeatures2D.java. It encapsulates an enum class MorphometricFeatures2D.Feature. This enumeration lists the different features that can be computed with the AnalyzeRegions plugin. Then, the computeTable method populates the results table from an ImagePlus containing a 2D label map.
In practice, most of the computations are performed within specialized feature analyzers (like Centroid, EquivalentEllipse...). The MorphometricFeatures2D.computeTable method calls them is the appropriate way (to manage dependencies), then populates the table from the various results.

from morpholibj.

tischi avatar tischi commented on July 17, 2024

I see!

    public MorphometricFeatures2D add(Feature f)
    {
        features.add(f);
        return this;
    }

I guess this does the trick?! Isn't that some kind of builder pattern?

from morpholibj.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.