Macro on imageJ, loop does not move to the next ROI - macros

I'm trying to crop sections in an image and then averaging all of them. I'm recycling my previous macros on imageJ. Previous macros work well by doing loops in a list of ROIs. But, for this one, I can't understand why the loop does not move to the next ROI in the list. Instead, I got the job N-times as the number of ROIs I have in the list but the macro uses the first ROI information. This is my macro:
runMacro("OpenROI");
rename("AA");
selectWindow("AA");
n=roiManager("count");
for(i=0;i<n;i++){
roiManager("select",i);
run("Copy");
run("Internal Clipboard");
rename(i);
}
selectWindow("AA");
run("Close");
run("Images to Stack", "name=Stack title=[] use");
run("Z Project...", "projection=[Average Intensity]");
Someone can catch what am I losing it? Thanks

I found a solution, the line:
selectWindow("AA");
must be inside the loop in order to set the ROI on the image. Full code is as follows:
runMacro("OpenROI");
rename("AA");
n=roiManager("count");
for(i=0;i <n; i++){
selectWindow("AA");
roiManager("select",i);
run("Copy");
run("Internal Clipboard");
rename(i);
}
selectWindow("AA");
run("Close");
run("Images to Stack", "name=Stack title=[] use");
run("Z Project...", "projection=[Average Intensity]");

Related

Confused about get_rays function in NeRF

I've been trying to understand NeRF. I finished reading the paper(Tancik) and watched some of the videos. I have been looking at some parts of the code. However, I can't quite wrap my head around what the get_rays function does in terms of the code. Could anybody just run through line-by-line about what each line in the the get_rays function is supposed to do?
def get_rays(H,W , focal, c2w): #c2w is pose
i, j = tf.meshgrid(tf.range(W, dtype=tf.float32), tf.range(H, dtype=tf.float32), indexing='xy')
dirs = tf.stack([(i-W*.5)/focal, -(j-H*.5)/focal, -tf.ones_like(i)], -1)
rays_d = tf.reduce_sum(dirs[..., np.newaxis, :] * c2w[:3,:3], -1)
rays_o = tf.broadcast_to(c2w[:3,-1], tf.shape(rays_d))
return rays_o, rays_d
It creates two lists, rays_o represents points where rays originate (camera centre) and rays_d represents direction vectors of each ray casting through the centre of every pixel of the camera. In this case, all values in the rays_o are the same because the function gets rays from a single camera.

rnd:weighted-one-of-list work doesn't return the distribution I think it should

I trying to use the rnd extension's function weighted-one-of-list.
My list looks like
observer>show female-yr-run-stats
observer: [[117 0.001169] [118 0.002684] [119 0.004697] [120 0.003368] [121 0.004871] [122 0.018738] [123 0.034986] [124 0.070616] [125 0.035608] [126 0.012939] [127 0.011883] [128 0.016594] [129 0.068837] [130 0.044391] [131 0.028422] [132 0.053251] [133 0.023741] [134 0.042111] [135 0.035811] [136 0.022447] [137 0.031563] [138 0.024253] [139 0.030213] [140 0.024372] [141 0.033266] [142 0.059869] [143 0.028711] [144 0.030863] [145 0.04043] [146 0.008819] [147 0.012308] [148 0.008638] [149 0.021345] [150 0.016176] [151 0.009815] [152 0.017242] [153 0.014362] [154 0.010717] [155 0.015868] [156 0.003865] [157 0.008441] [158 0.004358] [159 0.003113] [160 0.002464] [161 0.001768]]
The first item is day-of-the-year and the second is the probability (all sum to one).
I am using the code
repeat 50000[
let tempo first rnd:weighted-one-of-list female-yr-run-stats [ [p] -> last p ]
file-open "C://temp//check_wgt_random.csv"
file-print (word tempo)
file-close
]
to randomly select a day-of-the-year 50000 times to check that the rnd:weighted-one-of-list function is doing what I want it to do. From the results, I get a distribution of day-of-the-year. But when I compare the resulting distribution to the original probability distribution, they are quite different.
I am thinking that the rnd:weighted-one-of-list with my list would be equivalent to randomly drawing from a multinomial distribution like R's rmultinom function. Am I correct? Am I doing something wrong?
Any help would be appreciated.
The graph below shows the comparisons
The rnd:weighted-one-of-list primitive works the way (I think) you think it works. From your data, it draws the value 112 with probability 3.04E-4, value 113 with probability 0.001236 etc. The probabilities don't have to add to 1 (I have assumed that you are correct that yours do). I can't see anything wrong with your use of this primitive for your draws.
But I am not sure about the file construction. You have the file-open and file-close inside the repeat so the file is opened, the new data is appended, the file is closed. It is not clear whether you ever clear the dataset. So perhaps the problem is that you have some data left over from when you were building your code. Do you get the same problem if you clear out all the old data and start again?
Sorry to waste your time. I discovered what happened. I had two probabilities stream mixed up.

Making a support structure "manifold" in openscad

I am trying to build a support structure around a cylinder in openscad, but I cannot seem to make the angled part of the structure "manifold"
inner_slide_tube_inner_radius=14.9/2;
leadpipe_wall_thickness=14.9/2;
leadpipe_length=200;
mouthpiece_receiver_large_radius=0.546*25.4/2;
NoSpokes = 4;
SpokesWide = 3;
SpokesHigh = 3;
SpokesLong = leadpipe_length/2*0.75;
SpokesLong2 = leadpipe_length/2;
//if I comment out this section, then I can render a single support angle part when NoSpokes=1
for (i=[1:NoSpokes])
rotate([0,0,360/NoSpokes*i])
translate([mouthpiece_receiver_large_radius+leadpipe_wall_thickness,-SpokesWide/2,0])
cube([SpokesLong, SpokesWide, SpokesHigh]);
//
for (i=[1:NoSpokes])
rotate([0,0,360/NoSpokes*i])polyhedron(
points=[
[mouthpiece_receiver_large_radius+SpokesLong+leadpipe_wall_thickness-SpokesHigh, -SpokesWide/2, SpokesHigh],
[mouthpiece_receiver_large_radius+SpokesLong+leadpipe_wall_thickness-SpokesHigh, SpokesWide/2, SpokesHigh],
[inner_slide_tube_inner_radius, SpokesWide/2, SpokesLong2],
[inner_slide_tube_inner_radius, -SpokesWide/2, SpokesLong2],
[mouthpiece_receiver_large_radius+SpokesLong+leadpipe_wall_thickness, -SpokesWide/2, SpokesHigh],
[mouthpiece_receiver_large_radius+SpokesLong+leadpipe_wall_thickness, SpokesWide/2, SpokesHigh],
[inner_slide_tube_inner_radius, SpokesWide/2, SpokesLong2+SpokesHigh],
[inner_slide_tube_inner_radius, -SpokesWide/2, SpokesLong2+SpokesHigh]],
faces=[[1,0,3,2],
[1,5,4,0],
[2,3,7,6],
[1,5,6,2],
[0,4,7,3],
[4,5,6,7]
]);
I know that this is really naive question, but I am rather stuck as I keep getting the warning WARNING: Object may not be a valid 2-manifold and may need repair!
Any help would be greatly appreciated to get rid of the warning.
The reason your design is not manifold is that some of your polygon don't have the correct winding order. In OpenSCAD, if you preview your design using F2 (Thrown Together), such wrongly winded polygons will be highlighted in pink.

Line chart/graph with an irregular threshold field

Looking to create a bar chart with an irregular, colored threshold field in the background, so that each data point has its own individual set of min/max thresholds, which ultimately would look something like this: http://dcalvitti.webs.com/plant/SAMPLE.png
Looked at D3 examples like this one: http://bl.ocks.org/mbostock/4062844
Can the latter example be manipulated to look more like the image I created?
Thanks in advance..
The graph shown in your sample image is actually much easier than the linked example; for that, you don't need to create a clipping path and you don't need to draw the line twice with two different colours.
For drawing the coloured background, use an area-path generator, created with d3.svg.area(). Set the y0 accessor function to be extract your minimum value for each point in your data array, and the y1 accessor function to extract the maximum value.
Then draw the line overtop as a normal line graph with a d3.svg.line() path generator.
Working example, adapted from the fiddles in the comments: http://jsfiddle.net/h45CD/12/
(Note: I commented out half the dataset, since the "year" values were repeated, not sure what that was supposed to represent.)
Key code:
// Define the value line path generator
var line = d3.svg.line()
.x( function(d) { return x(d.year); } )
.y( function(d) { return y(d.temp); } );
// Define the area path generator
var area = d3.svg.area()
.x( function(d) { return x(d.year); } )
.y0( function(d) { return y(d.min); } )
.y1( function(d) { return y(d.max); } );
/* ... */
// Add the background area showing the historic range
svg.append("path")
.datum(data)
.attr("class", "historicRange")
.attr("d", area);
// Add the value line
svg.append("path")
.datum(data)
.attr("class", "dataline")
.attr("d", line);
Edit based on comments
If you do want a line that changes colour depending on historic values, as opposed to a line drawn overtop of a background range, the most straight-forward solution is probably to create a <pattern> element consisting of the different coloured regions, and use this to stroke the value line.
You'll want to familiarize yourself with the different options for the pattern element. This MDN tutorial has a good intro, or you could dive into the full W3 specs.
For this situation, we want the pattern to be sized and positioned relative to the coordinate system used for drawing the line, regardless of the size or shape of the line itself. That means we will be setting both the patternUnits and the patternContentUnits to be userSpaceOnUse. The height and width of the pattern will be the height and width of the plotting area.
Within the pattern we will draw the area that represents the max-min range, but we also need to draw separate areas, with different colours, for values above the max and values below the min. We can use the same area generator for each, but need to change the y0/y1 accessor functions each time.
Key code:
// Add the pattern showing the historic range
var pattern = defs.append("pattern")
.datum(data) //add the data to the <pattern> element
//so it will be inherited by each <path> we append
.attr({
"patternUnits":"userSpaceOnUse",
"patternContentUnits":"userSpaceOnUse",
"width": width,
"height": height
})
.attr("id", "strokePattern");
pattern.append("path")
.attr("class", "historicRange between")
.attr("d", area);
pattern.append("path")
.attr("class", "historicRange above")
.attr("d", area.y1( 0 )
.y0( function(d){return y(d.max);} )
);
pattern.append("path")
.attr("class", "historicRange below")
.attr("d", area.y1( function(d){return y(d.min);} )
.y0( height )
);
// Add the value line
plot.append("path")
.datum(data)
.attr("class", "dataline")
.attr("d", line)
.style("stroke", "url(#strokePattern)");
Working example: http://jsfiddle.net/h45CD/14/
I'm including a web page link with charts authored by myself based on AMCharts and with the help of that web site's founder. Contains several examples of the above question and more..
http://dcalvitti.webs.com/SAMPLE/NEWWEBINDEX.html
The charts provided are still being worked on. For example, AMcharts does have a function that clips the color of a line above/below a certain value which I didn't know about, so there is still work to be done. I spent many weeks on the charts and thought I'd share. I'm sure someone will find something new here down the road...

transitioning lines in d3.js

Sorry if this question seems stupid, but it's stumped me for a couple days, so I would really appreciate any simple input from anyone! :)
I'm trying to construct a line graph in d3.js that transitions between different datasets. However, whenever I hit the transition function, it selects the original line on the graph, AND the axes of the graph, and transitions all of it. I tried to do selectAll("svg:path") instead of selectAll("path") but it just returned a DOMException 12, indicating that the selection didn't exist.
//beginning of code to append axis to graph
graph.append("svg:g").attr("class", "x axis")
//draws the original line on the graph
graph.append("svg:path").attr("d", line(dataset1));
//line function
var line = d3.svg.line()
.x(function(d) {return x(d.age);})
.y(function(d) {return y(d.freq);})
.interpolate("basis");
//transition function
function transition(newData) {
graph.selectAll("path")
.data(newData)
.transition()
.duration(2000)
.attr("d", line(newData));
}
Thanks for any responses! :)
Just give the thing you want to change a unique class/identifier, e.g.
graph.append("svg:path").attr("d", line(dataset1)).classed("line", true);
...
graph.selectAll("path.line")
.data(newData)
...