Login  Register

Re: Problem with drawLine

Posted by BenTupper on Jul 20, 2010; 12:17pm
URL: http://imagej.273.s1.nabble.com/Problem-with-drawLine-tp3687544p3687545.html

Hi,

In version 1.44d it appears that drawLine accepts pixel coordinates  
where the origin is at the upper left regardless how how the origin is  
specified in the properties.  I don't know if that is intentional or  
not and the online docs don't mention it. One way around that might be  
something like the following...


//newImage("Test", "8-bit Black", 1182, 963, 1);
w = getWidth();
h = getHeight();
xc = w/2;
yc = h/2;
run("Properties...", "pixel_height=1 pixel_width=1 origin="+xc+","+yc);

n = 30;
dx = w/n;
dy = h/n;
for (i = 0; i <n; i++){
  y = i * dy;
        drawLine(0, y, w, y);
}


Cheers,
Ben


On Jul 20, 2010, at 4:34 AM, Luis Isaac Ramos Garcia wrote:

>   Dear Colleges;
>
>   First, I am new with ImageJ and its macro language so sorry if  
> this is a not interesting.
>
>   I would like to draw a line in a centered image, i.e. the origin  
> of the coordinates is not the left upper corner instead is more or  
> less the center of the image.
>   The center is at (1182,963) in a 2369x1928 image.
>
>   When I tried the following lines the macro does not work:
>                 setColor(255, 0, 0);
>       setLineWidth(1);
>       i=0;
>       x1=round((i-14)*(10/0.17));
>       y1=-750;
>       x2=x1;
>       y2=750;
>       drawLine(x1,y1,x2,y2);
>
>   Instead if I take the origin of the coordinates the left upper  
> corner the macro works:
>
>      setColor(255, 0, 0);
>       setLineWidth(1);
>       i=0;
>       x1=round((i-14)*(10/0.17));
>       y1=-750;
>       x2=x1;
>       y2=750;
>       drawLine(x1,y1,x2,y2);
>
>   But the if I change the 14 in the third line by 13....:
>
>      setColor(255, 0, 0);
>       setLineWidth(1);
>       i=0;
>       x1=round((i-13)*(10/0.17));
>       y1=-750;
>       x2=x1;
>       y2=750;
>       drawLine(x1,y1,x2,y2);
>
>   It does not work again.
>     At the end I suppose that there is a concept fail on the use of  
> drawLine but I don't know.
>
>   PD: I use i the code because in the next step I want to draw 29  
> lines in a 1cm step
>
>   Dear Colleges;
>
>   First, I am new with ImageJ and its macro language so sorry if  
> this is a not interesting.
>
>   I would like to draw a line in a centered image, i.e. the origin  
> of the coordinates is not the left upper corner instead is more or  
> less the center of the image.
>   The center is at (1182,963) in a 2369x1928 image.
>
>   When I tried the following lines the macro does not work:
>                 setColor(255, 0, 0);
>       setLineWidth(1);
>       i=0;
>       x1=round((i-14)*(10/0.17));
>       y1=-750;
>       x2=x1;
>       y2=750;
>       drawLine(x1,y1,x2,y2);
>
>   Instead if I take the origin of the coordinates the left upper  
> corner the macro works:
>
>      setColor(255, 0, 0);
>       setLineWidth(1);
>       i=0;
>       x1=round((i-14)*(10/0.17));
>       y1=-750;
>       x2=x1;
>       y2=750;
>       drawLine(x1,y1,x2,y2);
>
>   But the if I change the 14 in the third line by 13....:
>
>      setColor(255, 0, 0);
>       setLineWidth(1);
>       i=0;
>       x1=round((i-13)*(10/0.17));
>       y1=-750;
>       x2=x1;
>       y2=750;
>       drawLine(x1,y1,x2,y2);
>
>   It does not work again.
>     At the end I suppose that there is a concept fail on the use of  
> drawLine but I don't know.
>
>   PD: I use "i" the code because in the next step I want to draw 29  
> lines,  i. e. I would like to use these sentences in a for loop
>
>
>   Many Thanks,
>
> --
> Dr Luis Isaac Ramos Garcia
> Departamento de Oncologia
> Clinica Universidad de Navarra
> Facultad de Medicina,Universidad de Navarra
> Av. Pio XII nÂș36, 31008 Pamplona, Spain
> Fax: +34 948255500
> TEL: +34 948255400 (Ext. 4924)
> E-mail: [hidden email]
> Web Page: http://www.cun.es