Login  Register

get continuous pixel coordinates from a line ROI

Posted by albertoduina@virgilio.it on Aug 22, 2013; 2:47pm
URL: http://imagej.273.s1.nabble.com/get-continuous-pixel-coordinates-from-a-line-ROI-tp5004533.html

Hi all,
this question appear many times in the mailing list and Wayne has posted a  
macro for the solution.
This is a plugin subroutine prototype for the same problem, it works BUT  
if the Roi is an oblique line the profiX and the profiZ arrays have  
different length (profiZ 1 element more than profiX). If the start and end  
of the oblique line are on the image boundaries the last element of profiZ  
is every time 0 (i have tested many times).
Other than that the subroutine work apparently well.


//------------------------------------
        public static double[][] decomposer(ImagePlus imp1) {

                Line line = (Line) imp1.getRoi();
                if (line == null || !(line.isLine())) {
                        IJ.error("Line selection required.");
                        return null;
                }
                double[] profiZ = line.getPixels();

                // now for obtain the pixels coordinate i need a PolygonRoi
                float[] xcoord = new float[2];
                float[] ycoord = new float[2];
                xcoord[0] = (float) line.x1d;
                ycoord[0] = (float) line.y1d;
                xcoord[1] = (float) line.x2d;
                ycoord[1] = (float) line.y2d;
                imp1.setRoi(new PolygonRoi(xcoord, ycoord, 2, Roi.POLYLINE));
                PolygonRoi polyline = (PolygonRoi) imp1.getRoi();
                polyline.fitSplineForStraightening();
                FloatPolygon fp1 = polyline.getFloatPolygon();
                int len = fp1.xpoints.length;
                double[] profiX = new double[len];
                double[] profiY = new double[len];
                for (int i1 = 0; i1 < len; i1++) {
                        profiX[i1] = (double) fp1.xpoints[i1];
                        profiY[i1] = (double) fp1.ypoints[i1];
                }
                if (profiX.length != profiZ.length) {
                        IJ.log("different length, profi2x= " + profiX.length
                                        + " profi2z= " + profiZ.length);
                }
                double[][] out1 = new double[3][profiX.length];
                out1[0] = profiX;
                out1[1] = profiY;
                out1[2] = profiZ;
                return out1;
        }
//----------------------------------

Can somebody suggest a workaround for have a perfect plugin solution?
Thanks
Alberto Duina

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html