Posted by
CARL Philippe (LBP) on
Jan 05, 2017; 9:22am
URL: http://imagej.273.s1.nabble.com/overlays-tp5017831p5017839.html
Dear Len,
If you do "Help->Update_ImageJ..." and from there you choose the "daily build" version you will end up with the version v1.51j9.
And I tried the macro Wayne sent you on this daily build version and it is working as a charm.
And the same macro is not working properly if you stay within the version 1.51i.
My best regards,
Philippe
-----Message d'origine-----
De : ImageJ Interest Group [mailto:
[hidden email]] De la part de Dobens, Leonard
Envoyé : jeudi 5 janvier 2017 01:33
À :
[hidden email]
Objet : Re: overlays
A couple of problems in running your macro. The 1.51j version is not available, only 1.51i. Also when I do run your macro in “i” version, the command "Roi.setStrokeColor(255, 0, 0);” is not happy with RGB values - appears that only hex numbers are allowed (Does the “j” version permit RGB? that could address my problems).
I recognized that Roi.setStrokeColor() arrows drawn manually and colored by a hex value could be overplayed properly and I have tried to put together a hex converter for my RGB values, and while that change in the macro effectively removes the green arrows, the colors are now black with a couple of blue arrows, so my hex converter (as written) is not good.
The “green arrows” that come from the macro code cited below:
run("Color Picker...");
setForegroundColor(r, g, b);
makeArrow(xt, yt, xh, yh, "notched"); Roi.setStrokeWidth(width); Overlay.addSelection(); Overlay.copy; may result from a "select arrow” appearance (green), that if I could “de-select” all, may reveal their underlying proper color
Len
On Jan 3, 2017, at 10:17 PM, Rasband, Wayne (NIH/NIMH) [E] <
[hidden email]<mailto:
[hidden email]>> wrote:
On Jan 3, 2017, at 5:36 PM, Dobens, Leonard <
[hidden email]<mailto:
[hidden email]>> wrote:
I’ve written a macro that identifies hairs in a photomicrograph, outlines them and draws colored arrows across their Feret’s width with the arrowhead pointing to the thin end of the hair and with a color assigned correlating with the Feret’s angle (calculated over 360 degrees).
I’d like to overlay these arrow on the original image. It works well with a simpler macro making all the arrows are black or all are white, but when I used the colored arrows macro, the overlay is converted to green. Any idea why?
It would be very helpful if you could provide a small, self-contained macro that reproduces the problem. The following macro works as expected. It requires the latest ImageJ daily build (1.51j9), which adds the Roi.setStrokeColor(r,g,b) macro function.
-wayne
requires("1.51j");
newImage("Untitled", "8-bit black", 720, 576, 1); makeArrow(337, 85, 205, 212, "notched large"); Roi.setStrokeWidth(3); Roi.setStrokeColor(255, 200, 100); run("Add Selection..."); makeArrow(50, 130, 185, 213, "notched large"); Roi.setStrokeWidth(3); Roi.setStrokeColor(255, 0, 0); run("Add Selection..."); makeArrow(201, 435, 195, 240, "notched large"); Roi.setStrokeWidth(3); Roi.setStrokeColor(50, 100, 255); run("Add Selection..."); Overlay.copy; wait(2000); close; run("Boats (356K)"); Overlay.paste;
Here’s the very end of the macro (whole macro below)
for (i=0; i<nResults; i++) {
r = getResult("R",i);
g = getResult("G",i);
b = getResult("B",i);
xh = getResult("xh",i);
xt = getResult("xt",i);
yh = getResult("yh",i);
yt = getResult("yt",i);
run("Draw", "slice");
setTool("arrow");
run("Color Picker...");
setForegroundColor(r, g, b);
makeArrow(xt, yt, xh, yh, "notched"); Roi.setStrokeWidth(width); Overlay.addSelection(); Overlay.copy; } run("Close"); open(path_name); run("Color Picker..."); setForegroundColor(r, g, b); Overlay.paste;
/////////////////////////////////////////
Here’s the whole macro
var path_name = getDirectory("image")+ getInfo("image.filename");
run("Revert");
setAutoThreshold("Default");
run("Set Measurements...", "centroid center feret's redirect=None decimal=3"); run("Analyze Particles...", " show=[Overlay Outlines] display exclude clear"); run("To ROI Manager"); roiManager("Show All without labels");
title = "Untitled";
width=512; height=512;
Dialog.create("Set Arrow");
Dialog.addNumber("Width:", 51);
Dialog.show();
width = Dialog.getNumber();
resetThreshold();
Overlay.drawLabels(false);
for (i=0; i<nResults; i++) {
x11 = getResult("FeretX",i);
y11 = getResult("FeretY",i);
length = getResult("Feret",i);
degrees = getResult("FeretAngle",i);
if (degrees>90)
degrees -= 180;
angle = degrees*PI/180;
x21 = x11 + cos(angle)*length;
setResult("x21", i, x21);
y21 = y11 - sin(angle)*length;
setResult("y21", i, y21);
x31 = getResult("X",i);
y31 = getResult("Y",i);
makeLine(x31, y31, x11, y11);
getPixelSize(unit, pw, ph);
dz = (x31 - x11)*pw;
da = (y31 - y11)*ph;
distance1 = sqrt(dz*dz + da*da);
setResult("D1", i, distance1);
updateResults;
makeLine(x31, y31, x21, y21);
getPixelSize(unit, pw, ph);
dx = (x31 - x21)*pw;
dy = (y31 - y21)*ph;
distance2 = sqrt(dx*dx + dy*dy);
setResult("D2", i, distance2);
updateResults;
}
for (i=0; i<nResults; i++) {
D1 = getResult("D1",i);
D2 = getResult("D2",i);
x11 = getResult("FeretX",i);
y11 = getResult("FeretY",i);
x21 = getResult("x21",i);
y21 = getResult("y21",i);
if (D1 > D2) {
setResult("xh", i, x11);
setResult("xt", i, x21);
setResult("yh", i, y11);
setResult("yt", i, y21);
updateResults;setTool("arrow");
} else {
setResult("xh", i, x21);
setResult("xt", i, x11);
setResult("yh", i, y21);
setResult("yt", i, y11);
}
}
for (i=0; i<nResults; i++) {
xh = getResult("xh",i);
xt = getResult("xt",i);
yh = getResult("yh",i);
yt = getResult("yt",i);
degrees = getResult("FeretAngle",i);
if (xh > xt && yh < yt){
angle2 = degrees + 180;
setResult("angle360", i, angle2);
updateResults;
}
if (xh < xt && yh > yt){
angle2 = degrees + 0;
setResult("angle360", i, angle2);
updateResults;
}
if (xh > xt && yh > yt){
angle2 = degrees + 0;
setResult("angle360", i, angle2);
updateResults;
}
if (xh < xt && yh < yt){
angle2 = degrees + 180;
setResult("angle360", i, angle2);
}
}
run("RGB Color");
for (i=0; i<nResults; i++) {
a = getResult("angle360",i);
if (0 < a && a < 60){
r = 255;
g = 4.25*a;
b = 0;
setResult("R", i, r);
setResult("G", i, g);
setResult("B", i, b);
updateResults;
}
if (61 < a && a < 120){
r = -4.25*a + 510;
g = 255;
b = 0;
setResult("R", i, r);
setResult("G", i, g);
setResult("B", i, b);
updateResults;
}
if (121 < a && a< 180){
r = 0;
g = 255;
b = 4.25*a - 510;
setResult("R", i, r);
setResult("G", i, g);
setResult("B", i, b);
updateResults;
}
if (181 < a && a < 240){
r = 0;
g = -4.25*a + 1020;
b = 255;
setResult("R", i, r);
setResult("G", i, g);
setResult("B", i, b);
updateResults;
}
if (241 < a && a < 300){
r = 4.25*a - 1020;
g = 0;
b = 255;
setResult("R", i, r);
setResult("G", i, g);
setResult("B", i, b);
updateResults;
}
if (301 < a && a < 360){
r = 255;
g = 0;
b = -4.25*a + 1530;
setResult("R", i, r);
setResult("G", i, g);
setResult("B", i, b);
updateResults;
}
}
for (i=0; i<nResults; i++) {
r = getResult("R",i);
g = getResult("G",i);
b = getResult("B",i);
xh = getResult("xh",i);
xt = getResult("xt",i);
yh = getResult("yh",i);
yt = getResult("yt",i);
run("Draw", "slice");
setTool("arrow");
run("Color Picker...");
setForegroundColor(r, g, b);
makeArrow(xt, yt, xh, yh, "notched"); Roi.setStrokeWidth(width); Overlay.addSelection(); Overlay.copy; } run("Close"); open(path_name); run("Color Picker..."); setForegroundColor(r, g, b); Overlay.paste;
Len Dobens
Leonard Dobens, PhD
Professor of Molecular Biology and Biochemistry
SCB312
School of Biological Sciences
University of Missouri-Kansas City
5007 Rockhill Road
Kansas City, MO 64110
8162356272
[hidden email]<mailto:
[hidden email]><mailto:
[hidden email]>
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.htmlLeonard Dobens, PhD
Professor of Molecular Biology and Biochemistry
SCB312
School of Biological Sciences
University of Missouri-Kansas City
5007 Rockhill Road
Kansas City, MO 64110
8162356272
[hidden email]<mailto:
[hidden email]>
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html