How to center an ellipse?

Posted by Juanjo Vega on
URL: http://imagej.273.s1.nabble.com/How-to-center-an-ellipse-tp3685070.html

Hello!

I'm trying to center an ellipse ROI in an ImagePlus.

I have the following method, which gets a ROI, fits an ellipse, sets it's center (x and y), and then tries to refresh it, so the ellipse will be moved to the center of the image:

    public void fitEllipse() {
        Roi roi = ip.getRoi();

        if (roi != null && roi.isArea()) {
            IJ.run(ip, "Fit Ellipse", "");
            ImageStatistics is = ip.getStatistics();
            EllipseFitter ef = new EllipseFitter();
            ef.fit(ip.getProcessor(), is);

            // Builds an ellipse...
            ef.xCenter = ip.getHeight() / 2;
            ef.yCenter = ip.getHeight() / 2;

//            IJ.run("Select None");
            ef.makeRoi(ip.getProcessor());
        }
    }

The last part doesn't work and I'm sort of ideas. Does anybody can help me, please?

Have a nice weekend,

Juanjo.

------------------------------------------------------------
Juanjo Vega ([hidden email])

Unidad de Biocomputación. Laboratorio B-13.
Centro Nacional de Biotecnología. CNB-CSIC.
C\ Darwin, 3. Campus de Cantoblanco.
Universidad Autónoma de Madrid.
28049, Madrid, Spain.

http://www.cnb.csic.es
http://www.biocomp.cnb.csic.es

+34 91 585 4510

"Las mejores almas son capaces de los mayores vicios como de las mayores
virtudes, y aquellos que caminan despacio por el camino recto pueden
llegar más lejos que los que corren pero se apartan de él." - Discurso
del Método, René Descartes.