Greetings,
See plugin below: On windows: fh = 16 tb = java.awt.Rectangle[x=128,y=128,width=1,height=1] although Edit>Selection>Properties...(List coordinates) lists the correct coordinates The IJ.run(imp."Draw","slice"); draws the text in the correct justified position. On Linux: fh = 15 tb = java.awt.Rectangle[x=128,y=128,width=48,height=24] The IJ.run(imp,"Draw","slice"); always draws the text in the LEFT justified position. On both OSs uncommenting troi.drawPixels and commenting the IJ.run... does not draw anything. I need to justify both horizontally(Left,CENTER,RIGHT) and vertically(TOP,CENTER,BOTTOM). On Linux with the correct extracted information I can do the justifications, although not on windows. Thanks in advance, Fred -=-=-=-=-=-=-=-=-=-=-=-=-= import ij.*; import ij.process.*; import ij.gui.*; import java.awt.*; import ij.plugin.*; import ij.plugin.frame.*; public class Test_TextRoi implements PlugIn { public void run(String arg) { ImagePlus imp = IJ.createImage("TestTextRoi", "RGB black", 256, 256, 1); IJ.run(imp, "Macro...", "code=[if (d<3) v=255]"); imp.show(); FontMetrics metrics = imp.getProcessor().getFontMetrics(); int fh = metrics.getHeight(); IJ.log("fh = "+fh); TextRoi troi = new TextRoi(128,128,"Hello"); imp.setRoi(troi); //troi.setStrokeColor(Toolbar.getForegroundColor()); //troi.setStrokeColor(Color.green); troi.setJustification(TextRoi.CENTER); Rectangle tb = troi.getBounds(); IJ.log("tb = "+tb); //troi.drawPixels(imp.getProcessor()); //imp.show(); IJ.run(imp, "Draw", "slice"); imp.changes = false; } } -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
> On Feb 18, 2020, at 10:06 PM, Fred Damen <[hidden email]> wrote:
> > Greetings, > > See plugin below: The latest ImageJ daily build (1.52u17) fixes bugs in TextRoi.setJustification() and TextRoi.drawPixel(). TextRoi.drawPixel() now draws using the foreground color if the color has not been set using ip.setColor(Color). Here is some JavaScript code that reproduces the problems: imp = IJ.createImage("TestTextRoi", "RGB black", 256, 256, 1); IJ.run(imp, "Macro...", "code=[if (d<3) v=255]"); troi = new TextRoi(128,128,"Hello"); troi.setJustification(TextRoi.CENTER); imp.setRoi(troi); //imp.getProcessor().setColor(Color.cyan); troi.drawPixels(imp.getProcessor()); imp.show(); -wayne > On windows: > fh = 16 > tb = java.awt.Rectangle[x=128,y=128,width=1,height=1] > although Edit>Selection>Properties...(List coordinates) > lists the correct coordinates > The IJ.run(imp."Draw","slice"); draws the text in the correct justified > position. > > On Linux: > fh = 15 > tb = java.awt.Rectangle[x=128,y=128,width=48,height=24] > The IJ.run(imp,"Draw","slice"); always draws the text in the LEFT > justified position. > > On both OSs uncommenting troi.drawPixels and commenting the IJ.run... does > not draw anything. > > I need to justify both horizontally(Left,CENTER,RIGHT) and > vertically(TOP,CENTER,BOTTOM). > On Linux with the correct extracted information I can do the > justifications, although not on windows. > > Thanks in advance, > > Fred > > > -=-=-=-=-=-=-=-=-=-=-=-=-= > import ij.*; > import ij.process.*; > import ij.gui.*; > import java.awt.*; > import ij.plugin.*; > import ij.plugin.frame.*; > > public class Test_TextRoi implements PlugIn { > > public void run(String arg) { > ImagePlus imp = IJ.createImage("TestTextRoi", "RGB black", 256, 256, > 1); > IJ.run(imp, "Macro...", "code=[if (d<3) v=255]"); > imp.show(); > > FontMetrics metrics = imp.getProcessor().getFontMetrics(); > int fh = metrics.getHeight(); > IJ.log("fh = "+fh); > > TextRoi troi = new TextRoi(128,128,"Hello"); > imp.setRoi(troi); > //troi.setStrokeColor(Toolbar.getForegroundColor()); > //troi.setStrokeColor(Color.green); > troi.setJustification(TextRoi.CENTER); > Rectangle tb = troi.getBounds(); > IJ.log("tb = "+tb); > > //troi.drawPixels(imp.getProcessor()); > //imp.show(); > IJ.run(imp, "Draw", "slice"); > imp.changes = false; > } > > } -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Greetings Wayne,
Do you know of a workaround to get the correct bounding box dimensions? Rectangle tb = roi.getBounds(); On windows it defaults to a width=1 and height=1. Thanks, Fred On Wed, February 19, 2020 12:25 pm, Wayne Rasband wrote: >> On Feb 18, 2020, at 10:06 PM, Fred Damen <[hidden email]> wrote: >> >> Greetings, >> >> See plugin below: > > The latest ImageJ daily build (1.52u17) fixes bugs in > TextRoi.setJustification() and TextRoi.drawPixel(). TextRoi.drawPixel() > now draws using the foreground color if the color has not been set using > ip.setColor(Color). > > Here is some JavaScript code that reproduces the problems: > > imp = IJ.createImage("TestTextRoi", "RGB black", 256, 256, 1); > IJ.run(imp, "Macro...", "code=[if (d<3) v=255]"); > troi = new TextRoi(128,128,"Hello"); > troi.setJustification(TextRoi.CENTER); > imp.setRoi(troi); > //imp.getProcessor().setColor(Color.cyan); > troi.drawPixels(imp.getProcessor()); > imp.show(); > > -wayne > > >> On windows: >> fh = 16 >> tb = java.awt.Rectangle[x=128,y=128,width=1,height=1] >> although Edit>Selection>Properties...(List coordinates) >> lists the correct coordinates >> The IJ.run(imp."Draw","slice"); draws the text in the correct justified >> position. >> >> On Linux: >> fh = 15 >> tb = java.awt.Rectangle[x=128,y=128,width=48,height=24] >> The IJ.run(imp,"Draw","slice"); always draws the text in the LEFT >> justified position. >> >> On both OSs uncommenting troi.drawPixels and commenting the IJ.run... >> does >> not draw anything. >> >> I need to justify both horizontally(Left,CENTER,RIGHT) and >> vertically(TOP,CENTER,BOTTOM). >> On Linux with the correct extracted information I can do the >> justifications, although not on windows. >> >> Thanks in advance, >> >> Fred >> >> >> -=-=-=-=-=-=-=-=-=-=-=-=-= >> import ij.*; >> import ij.process.*; >> import ij.gui.*; >> import java.awt.*; >> import ij.plugin.*; >> import ij.plugin.frame.*; >> >> public class Test_TextRoi implements PlugIn { >> >> public void run(String arg) { >> ImagePlus imp = IJ.createImage("TestTextRoi", "RGB black", 256, >> 256, >> 1); >> IJ.run(imp, "Macro...", "code=[if (d<3) v=255]"); >> imp.show(); >> >> FontMetrics metrics = imp.getProcessor().getFontMetrics(); >> int fh = metrics.getHeight(); >> IJ.log("fh = "+fh); >> >> TextRoi troi = new TextRoi(128,128,"Hello"); >> imp.setRoi(troi); >> //troi.setStrokeColor(Toolbar.getForegroundColor()); >> //troi.setStrokeColor(Color.green); >> troi.setJustification(TextRoi.CENTER); >> Rectangle tb = troi.getBounds(); >> IJ.log("tb = "+tb); >> >> //troi.drawPixels(imp.getProcessor()); >> //imp.show(); >> IJ.run(imp, "Draw", "slice"); >> imp.changes = false; >> } >> >> } > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Dear Fred,
I'm under Windows 7 and get the expected values with the following Javascript code: imp = IJ.openImage("http://wsr.imagej.net/images/blobs.gif"); imp.setRoi(72,50,111,125); imp.show(); roi = imp.getRoi() tb = roi.getBounds(); IJ.log(tb.x); IJ.log(tb.y); IJ.log(tb.width); IJ.log(tb.height); My best regards, Philippe Philippe CARL Laboratoire de Bioimagerie et Pathologies UMR 7021 CNRS - Université de Strasbourg Faculté de Pharmacie 74 route du Rhin 67401 ILLKIRCH Tel : +33(0)3 68 85 42 89 ----- Le 19 Fév 20, à 22:09, Fred Damen [hidden email] a écrit : Greetings Wayne, Do you know of a workaround to get the correct bounding box dimensions? Rectangle tb = roi.getBounds(); On windows it defaults to a width=1 and height=1. Thanks, Fred On Wed, February 19, 2020 12:25 pm, Wayne Rasband wrote: >> On Feb 18, 2020, at 10:06 PM, Fred Damen <[hidden email]> wrote: >> >> Greetings, >> >> See plugin below: > > The latest ImageJ daily build (1.52u17) fixes bugs in > TextRoi.setJustification() and TextRoi.drawPixel(). TextRoi.drawPixel() > now draws using the foreground color if the color has not been set using > ip.setColor(Color). > > Here is some JavaScript code that reproduces the problems: > > imp = IJ.createImage("TestTextRoi", "RGB black", 256, 256, 1); > IJ.run(imp, "Macro...", "code=[if (d<3) v=255]"); > troi = new TextRoi(128,128,"Hello"); > troi.setJustification(TextRoi.CENTER); > imp.setRoi(troi); > //imp.getProcessor().setColor(Color.cyan); > troi.drawPixels(imp.getProcessor()); > imp.show(); > > -wayne > > >> On windows: >> fh = 16 >> tb = java.awt.Rectangle[x=128,y=128,width=1,height=1] >> although Edit>Selection>Properties...(List coordinates) >> lists the correct coordinates >> The IJ.run(imp."Draw","slice"); draws the text in the correct justified >> position. >> >> On Linux: >> fh = 15 >> tb = java.awt.Rectangle[x=128,y=128,width=48,height=24] >> The IJ.run(imp,"Draw","slice"); always draws the text in the LEFT >> justified position. >> >> On both OSs uncommenting troi.drawPixels and commenting the IJ.run... >> does >> not draw anything. >> >> I need to justify both horizontally(Left,CENTER,RIGHT) and >> vertically(TOP,CENTER,BOTTOM). >> On Linux with the correct extracted information I can do the >> justifications, although not on windows. >> >> Thanks in advance, >> >> Fred >> >> >> -=-=-=-=-=-=-=-=-=-=-=-=-= >> import ij.*; >> import ij.process.*; >> import ij.gui.*; >> import java.awt.*; >> import ij.plugin.*; >> import ij.plugin.frame.*; >> >> public class Test_TextRoi implements PlugIn { >> >> public void run(String arg) { >> ImagePlus imp = IJ.createImage("TestTextRoi", "RGB black", 256, >> 256, >> 1); >> IJ.run(imp, "Macro...", "code=[if (d<3) v=255]"); >> imp.show(); >> >> FontMetrics metrics = imp.getProcessor().getFontMetrics(); >> int fh = metrics.getHeight(); >> IJ.log("fh = "+fh); >> >> TextRoi troi = new TextRoi(128,128,"Hello"); >> imp.setRoi(troi); >> //troi.setStrokeColor(Toolbar.getForegroundColor()); >> //troi.setStrokeColor(Color.green); >> troi.setJustification(TextRoi.CENTER); >> Rectangle tb = troi.getBounds(); >> IJ.log("tb = "+tb); >> >> //troi.drawPixels(imp.getProcessor()); >> //imp.show(); >> IJ.run(imp, "Draw", "slice"); >> imp.changes = false; >> } >> >> } > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Philippe,
it is a TextRoi issue, normal rectangular rois are fine. Sample JavaScript: imp = IJ.createImage("TestTextRoi", "RGB black", 256, 256, 1); IJ.run(imp, "Macro...", "code=[if (d<3) v=255]"); troi = new TextRoi(128,128,"Hello"); troi.setJustification(TextRoi.CENTER); imp.setRoi(troi); IJ.log("before: bounds="+troi.getBounds()); //imp.getProcessor().setColor(Color.cyan); troi.drawPixels(imp.getProcessor()); imp.show(); IJ.log("finally: bounds="+troi.getBounds()); Under Linux I get before: bounds=java.awt.Rectangle[x=128,y=128,width=48,height=24] finally: bounds=java.awt.Rectangle[x=104,y=128,width=48,height=24] which is the correct width in both cases (this seems to be different from Windows), but the x position does not reflect the 'CENTER' justification before drawing the TextRoi (which I consider a minor flaw). After drawing, the x position is correct. Michael ________________________________________________________________ On 20.02.20 09:47, CARL Philippe (LBP) wrote: > Dear Fred, > I'm under Windows 7 and get the expected values with the following Javascript code: > imp = IJ.openImage("http://wsr.imagej.net/images/blobs.gif"); > imp.setRoi(72,50,111,125); > imp.show(); > roi = imp.getRoi() > tb = roi.getBounds(); > IJ.log(tb.x); > IJ.log(tb.y); > IJ.log(tb.width); > IJ.log(tb.height); > My best regards, > Philippe > > Philippe CARL > Laboratoire de Bioimagerie et Pathologies > UMR 7021 CNRS - Université de Strasbourg > Faculté de Pharmacie > 74 route du Rhin > 67401 ILLKIRCH > Tel : +33(0)3 68 85 42 89 > > ----- Le 19 Fév 20, à 22:09, Fred Damen [hidden email] a écrit : > > Greetings Wayne, > > Do you know of a workaround to get the correct bounding box dimensions? > Rectangle tb = roi.getBounds(); > On windows it defaults to a width=1 and height=1. > > Thanks, > > Fred > > On Wed, February 19, 2020 12:25 pm, Wayne Rasband wrote: >>> On Feb 18, 2020, at 10:06 PM, Fred Damen <[hidden email]> wrote: >>> >>> Greetings, >>> >>> See plugin below: >> >> The latest ImageJ daily build (1.52u17) fixes bugs in >> TextRoi.setJustification() and TextRoi.drawPixel(). TextRoi.drawPixel() >> now draws using the foreground color if the color has not been set using >> ip.setColor(Color). >> >> Here is some JavaScript code that reproduces the problems: >> >> imp = IJ.createImage("TestTextRoi", "RGB black", 256, 256, 1); >> IJ.run(imp, "Macro...", "code=[if (d<3) v=255]"); >> troi = new TextRoi(128,128,"Hello"); >> troi.setJustification(TextRoi.CENTER); >> imp.setRoi(troi); >> //imp.getProcessor().setColor(Color.cyan); >> troi.drawPixels(imp.getProcessor()); >> imp.show(); >> >> -wayne >> >> >>> On windows: >>> fh = 16 >>> tb = java.awt.Rectangle[x=128,y=128,width=1,height=1] >>> although Edit>Selection>Properties...(List coordinates) >>> lists the correct coordinates >>> The IJ.run(imp."Draw","slice"); draws the text in the correct justified >>> position. >>> >>> On Linux: >>> fh = 15 >>> tb = java.awt.Rectangle[x=128,y=128,width=48,height=24] >>> The IJ.run(imp,"Draw","slice"); always draws the text in the LEFT >>> justified position. >>> >>> On both OSs uncommenting troi.drawPixels and commenting the IJ.run... >>> does >>> not draw anything. >>> >>> I need to justify both horizontally(Left,CENTER,RIGHT) and >>> vertically(TOP,CENTER,BOTTOM). >>> On Linux with the correct extracted information I can do the >>> justifications, although not on windows. >>> >>> Thanks in advance, >>> >>> Fred >>> >>> >>> -=-=-=-=-=-=-=-=-=-=-=-=-= >>> import ij.*; >>> import ij.process.*; >>> import ij.gui.*; >>> import java.awt.*; >>> import ij.plugin.*; >>> import ij.plugin.frame.*; >>> >>> public class Test_TextRoi implements PlugIn { >>> >>> public void run(String arg) { >>> ImagePlus imp = IJ.createImage("TestTextRoi", "RGB black", 256, >>> 256, >>> 1); >>> IJ.run(imp, "Macro...", "code=[if (d<3) v=255]"); >>> imp.show(); >>> >>> FontMetrics metrics = imp.getProcessor().getFontMetrics(); >>> int fh = metrics.getHeight(); >>> IJ.log("fh = "+fh); >>> >>> TextRoi troi = new TextRoi(128,128,"Hello"); >>> imp.setRoi(troi); >>> //troi.setStrokeColor(Toolbar.getForegroundColor()); >>> //troi.setStrokeColor(Color.green); >>> troi.setJustification(TextRoi.CENTER); >>> Rectangle tb = troi.getBounds(); >>> IJ.log("tb = "+tb); >>> >>> //troi.drawPixels(imp.getProcessor()); >>> //imp.show(); >>> IJ.run(imp, "Draw", "slice"); >>> imp.changes = false; >>> } >>> >>> } >> >> -- >> ImageJ mailing list: http://imagej.nih.gov/ij/list.html >> > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Servus Michael,
How are you doing? With the daily build version of ImageJ (under Windows 7) I get the following result: before: bounds=java.awt.Rectangle[x=128,y=128,width=43,height=26] finally: bounds=java.awt.Rectangle[x=107,y=128,width=43,height=26] Kindest regards, Philippe ----- Mail original ----- De: "Michael Schmid" <[hidden email]> À: "imagej" <[hidden email]> Envoyé: Jeudi 20 Février 2020 10:01:25 Objet: Re: TextRoi issues Hi Philippe, it is a TextRoi issue, normal rectangular rois are fine. Sample JavaScript: imp = IJ.createImage("TestTextRoi", "RGB black", 256, 256, 1); IJ.run(imp, "Macro...", "code=[if (d<3) v=255]"); troi = new TextRoi(128,128,"Hello"); troi.setJustification(TextRoi.CENTER); imp.setRoi(troi); IJ.log("before: bounds="+troi.getBounds()); //imp.getProcessor().setColor(Color.cyan); troi.drawPixels(imp.getProcessor()); imp.show(); IJ.log("finally: bounds="+troi.getBounds()); Under Linux I get before: bounds=java.awt.Rectangle[x=128,y=128,width=48,height=24] finally: bounds=java.awt.Rectangle[x=104,y=128,width=48,height=24] which is the correct width in both cases (this seems to be different from Windows), but the x position does not reflect the 'CENTER' justification before drawing the TextRoi (which I consider a minor flaw). After drawing, the x position is correct. Michael ________________________________________________________________ On 20.02.20 09:47, CARL Philippe (LBP) wrote: > Dear Fred, > I'm under Windows 7 and get the expected values with the following Javascript code: > imp = IJ.openImage("http://wsr.imagej.net/images/blobs.gif"); > imp.setRoi(72,50,111,125); > imp.show(); > roi = imp.getRoi() > tb = roi.getBounds(); > IJ.log(tb.x); > IJ.log(tb.y); > IJ.log(tb.width); > IJ.log(tb.height); > My best regards, > Philippe > > Philippe CARL > Laboratoire de Bioimagerie et Pathologies > UMR 7021 CNRS - Université de Strasbourg > Faculté de Pharmacie > 74 route du Rhin > 67401 ILLKIRCH > Tel : +33(0)3 68 85 42 89 > > ----- Le 19 Fév 20, à 22:09, Fred Damen [hidden email] a écrit : > > Greetings Wayne, > > Do you know of a workaround to get the correct bounding box dimensions? > Rectangle tb = roi.getBounds(); > On windows it defaults to a width=1 and height=1. > > Thanks, > > Fred > > On Wed, February 19, 2020 12:25 pm, Wayne Rasband wrote: >>> On Feb 18, 2020, at 10:06 PM, Fred Damen <[hidden email]> wrote: >>> >>> Greetings, >>> >>> See plugin below: >> >> The latest ImageJ daily build (1.52u17) fixes bugs in >> TextRoi.setJustification() and TextRoi.drawPixel(). TextRoi.drawPixel() >> now draws using the foreground color if the color has not been set using >> ip.setColor(Color). >> >> Here is some JavaScript code that reproduces the problems: >> >> imp = IJ.createImage("TestTextRoi", "RGB black", 256, 256, 1); >> IJ.run(imp, "Macro...", "code=[if (d<3) v=255]"); >> troi = new TextRoi(128,128,"Hello"); >> troi.setJustification(TextRoi.CENTER); >> imp.setRoi(troi); >> //imp.getProcessor().setColor(Color.cyan); >> troi.drawPixels(imp.getProcessor()); >> imp.show(); >> >> -wayne >> >> >>> On windows: >>> fh = 16 >>> tb = java.awt.Rectangle[x=128,y=128,width=1,height=1] >>> although Edit>Selection>Properties...(List coordinates) >>> lists the correct coordinates >>> The IJ.run(imp."Draw","slice"); draws the text in the correct justified >>> position. >>> >>> On Linux: >>> fh = 15 >>> tb = java.awt.Rectangle[x=128,y=128,width=48,height=24] >>> The IJ.run(imp,"Draw","slice"); always draws the text in the LEFT >>> justified position. >>> >>> On both OSs uncommenting troi.drawPixels and commenting the IJ.run... >>> does >>> not draw anything. >>> >>> I need to justify both horizontally(Left,CENTER,RIGHT) and >>> vertically(TOP,CENTER,BOTTOM). >>> On Linux with the correct extracted information I can do the >>> justifications, although not on windows. >>> >>> Thanks in advance, >>> >>> Fred >>> >>> >>> -=-=-=-=-=-=-=-=-=-=-=-=-= >>> import ij.*; >>> import ij.process.*; >>> import ij.gui.*; >>> import java.awt.*; >>> import ij.plugin.*; >>> import ij.plugin.frame.*; >>> >>> public class Test_TextRoi implements PlugIn { >>> >>> public void run(String arg) { >>> ImagePlus imp = IJ.createImage("TestTextRoi", "RGB black", 256, >>> 256, >>> 1); >>> IJ.run(imp, "Macro...", "code=[if (d<3) v=255]"); >>> imp.show(); >>> >>> FontMetrics metrics = imp.getProcessor().getFontMetrics(); >>> int fh = metrics.getHeight(); >>> IJ.log("fh = "+fh); >>> >>> TextRoi troi = new TextRoi(128,128,"Hello"); >>> imp.setRoi(troi); >>> //troi.setStrokeColor(Toolbar.getForegroundColor()); >>> //troi.setStrokeColor(Color.green); >>> troi.setJustification(TextRoi.CENTER); >>> Rectangle tb = troi.getBounds(); >>> IJ.log("tb = "+tb); >>> >>> //troi.drawPixels(imp.getProcessor()); >>> //imp.show(); >>> IJ.run(imp, "Draw", "slice"); >>> imp.changes = false; >>> } >>> >>> } >> >> -- >> ImageJ mailing list: http://imagej.nih.gov/ij/list.html >> > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Michael Schmid
> On Feb 20, 2020, at 4:01 AM, Michael Schmid <[hidden email]> wrote:
> > Hi Philippe, > > it is a TextRoi issue, normal rectangular rois are fine. Sample JavaScript: > > imp = IJ.createImage("TestTextRoi", "RGB black", 256, 256, 1); > IJ.run(imp, "Macro...", "code=[if (d<3) v=255]"); > troi = new TextRoi(128,128,"Hello"); > troi.setJustification(TextRoi.CENTER); > imp.setRoi(troi); > IJ.log("before: bounds="+troi.getBounds()); > //imp.getProcessor().setColor(Color.cyan); > troi.drawPixels(imp.getProcessor()); > imp.show(); > IJ.log("finally: bounds="+troi.getBounds()); > > Under Linux I get > before: bounds=java.awt.Rectangle[x=128,y=128,width=48,height=24] > finally: bounds=java.awt.Rectangle[x=104,y=128,width=48,height=24] > > which is the correct width in both cases (this seems to be different from Windows), but the x position does not reflect the 'CENTER' justification before drawing the TextRoi (which I consider a minor flaw). > After drawing, the x position is correct. This bug is fixed in the ImageJ 1.52u21 daily build. The JavaScript now outputs before: bounds=java.awt.Rectangle[x=105,y=128,width=46,height=24] finally: bounds=java.awt.Rectangle[x=105,y=128,width=46,height=24] -wayne > > > Michael > ________________________________________________________________ > On 20.02.20 09:47, CARL Philippe (LBP) wrote: >> Dear Fred, >> I'm under Windows 7 and get the expected values with the following Javascript code: >> imp = IJ.openImage("http://wsr.imagej.net/images/blobs.gif"); >> imp.setRoi(72,50,111,125); >> imp.show(); >> roi = imp.getRoi() >> tb = roi.getBounds(); >> IJ.log(tb.x); >> IJ.log(tb.y); >> IJ.log(tb.width); >> IJ.log(tb.height); >> My best regards, >> Philippe >> Philippe CARL >> Laboratoire de Bioimagerie et Pathologies >> UMR 7021 CNRS - Université de Strasbourg >> Faculté de Pharmacie >> 74 route du Rhin >> 67401 ILLKIRCH >> Tel : +33(0)3 68 85 42 89 >> ----- Le 19 Fév 20, à 22:09, Fred Damen [hidden email] a écrit : >> Greetings Wayne, >> Do you know of a workaround to get the correct bounding box dimensions? >> Rectangle tb = roi.getBounds(); >> On windows it defaults to a width=1 and height=1. >> Thanks, >> Fred >> On Wed, February 19, 2020 12:25 pm, Wayne Rasband wrote: >>>> On Feb 18, 2020, at 10:06 PM, Fred Damen <[hidden email]> wrote: >>>> >>>> Greetings, >>>> >>>> See plugin below: >>> >>> The latest ImageJ daily build (1.52u17) fixes bugs in >>> TextRoi.setJustification() and TextRoi.drawPixel(). TextRoi.drawPixel() >>> now draws using the foreground color if the color has not been set using >>> ip.setColor(Color). >>> >>> Here is some JavaScript code that reproduces the problems: >>> >>> imp = IJ.createImage("TestTextRoi", "RGB black", 256, 256, 1); >>> IJ.run(imp, "Macro...", "code=[if (d<3) v=255]"); >>> troi = new TextRoi(128,128,"Hello"); >>> troi.setJustification(TextRoi.CENTER); >>> imp.setRoi(troi); >>> //imp.getProcessor().setColor(Color.cyan); >>> troi.drawPixels(imp.getProcessor()); >>> imp.show(); >>> >>> -wayne >>> >>> >>>> On windows: >>>> fh = 16 >>>> tb = java.awt.Rectangle[x=128,y=128,width=1,height=1] >>>> although Edit>Selection>Properties...(List coordinates) >>>> lists the correct coordinates >>>> The IJ.run(imp."Draw","slice"); draws the text in the correct justified >>>> position. >>>> >>>> On Linux: >>>> fh = 15 >>>> tb = java.awt.Rectangle[x=128,y=128,width=48,height=24] >>>> The IJ.run(imp,"Draw","slice"); always draws the text in the LEFT >>>> justified position. >>>> >>>> On both OSs uncommenting troi.drawPixels and commenting the IJ.run... >>>> does >>>> not draw anything. >>>> >>>> I need to justify both horizontally(Left,CENTER,RIGHT) and >>>> vertically(TOP,CENTER,BOTTOM). >>>> On Linux with the correct extracted information I can do the >>>> justifications, although not on windows. >>>> >>>> Thanks in advance, >>>> >>>> Fred >>>> >>>> >>>> -=-=-=-=-=-=-=-=-=-=-=-=-= >>>> import ij.*; >>>> import ij.process.*; >>>> import ij.gui.*; >>>> import java.awt.*; >>>> import ij.plugin.*; >>>> import ij.plugin.frame.*; >>>> >>>> public class Test_TextRoi implements PlugIn { >>>> >>>> public void run(String arg) { >>>> ImagePlus imp = IJ.createImage("TestTextRoi", "RGB black", 256, >>>> 256, >>>> 1); >>>> IJ.run(imp, "Macro...", "code=[if (d<3) v=255]"); >>>> imp.show(); >>>> >>>> FontMetrics metrics = imp.getProcessor().getFontMetrics(); >>>> int fh = metrics.getHeight(); >>>> IJ.log("fh = "+fh); >>>> >>>> TextRoi troi = new TextRoi(128,128,"Hello"); >>>> imp.setRoi(troi); >>>> //troi.setStrokeColor(Toolbar.getForegroundColor()); >>>> //troi.setStrokeColor(Color.green); >>>> troi.setJustification(TextRoi.CENTER); >>>> Rectangle tb = troi.getBounds(); >>>> IJ.log("tb = "+tb); >>>> >>>> //troi.drawPixels(imp.getProcessor()); >>>> //imp.show(); >>>> IJ.run(imp, "Draw", "slice"); >>>> imp.changes = false; >>>> } >>>> >>>> } -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |