How to do a line selection in fiji (imagej) using specified coords - imagej

How to select a line in an image using ImageJ/Fiji by setting its start and end points? As in not drawing it over the image, but inputting the coordinates directly somewhere.

open script editor, select IJ1 macro and then type the code below and then run.
makeLine(1, 1, 100, 100);
This will create a line ROI between (1,1) and (100, 100).
See
https://imagej.nih.gov/ij/developer/macro/functions.html#makeLine

Related

How to create a "spectrum" chart using Vaadin 14+

Is there a way in Vaadin 14 (or higher) to create what's called a "spectra" chart? Essentially, it's 99% identical to a "scatter" chart, except that a line is drawn from the point all the way down to the x-axis (please see figures 1 and 2 below which more or looks like a correct spectra chart.). I created a "hack" to achieve these quasi spectrum charts in Vaadin using "line charts" and by adding two "fake" points of intensity 0 to the left and to the right of my immediate point (as shown in code snippet below entitled "code snippet 1"). While my hack more-or-less works (pls see fig 1 image below), it causes a few problems: 1) it seems to make the lines appear more like bar-chart rectangles (please see fig 2) instead of points with narrow lines; 2) it seems to cause slight mistakes in the x-axis location. For example, in figure 2, the black line is to the left of the blue line; but in figure 3 (which is nothing more than the zoomed in perspective), it's to the right; and 3) it causes the x-axis to appear in the same color as the series, since my hack causes a line to appear to connect the fake right "0" of one point with the fake left "0" of the next point. (Plus, it means my chart has 3x the number of points than it needs to have, since I have two fake 0 points for every real point.)
Code snippet 1:
private void addTheSeries(DataSeries series, final float mz, final float intensity) {
//14.1.19
series.add(new DataSeriesItem(mz, 0));
series.add(new DataSeriesItem(mz, intensity));
series.add(new DataSeriesItem(mz, 0));
}
Figure 1:
Figure 2:
I'm using Vaadin 14.1.19 on Open jdk 11 and with Chrome on Chromebook as the browser.
I think it this case instead of using a Line type which is the default you'd benefit from using Column type. You can configure columns to be thin, configure zoomType and use axis configuration to get the extremes you want.
Chart chart = new Chart(ChartType.COLUMN);
Configuration configuration = chart.getConfiguration();
configuration.setTitle("Spectrum example");
configuration.getChart().setZoomType(Dimension.XY);
DataSeries series = new DataSeries();
series.add(new DataSeriesItem(120, 5));
series.add(new DataSeriesItem(180, 50));
series.add(new DataSeriesItem(290, 350));
series.add(new DataSeriesItem(420, 500));
series.add(new DataSeriesItem(740, 450));
PlotOptionsColumn options = new PlotOptionsColumn();
options.setPointWidth(1);
series.setPlotOptions(options);
configuration.addSeries(series);
YAxis y = configuration.getyAxis();
y.setTitle("");
configuration.getLegend().setEnabled(false);
add(chart);
Result looks like this:
And the width is kept after zooming in:

How to get a path's outline?

I have some point like below:
[[1,4],[2,8]]
[[5,4],[3,8],[5,4]]
Then I make a line (lat's say the width is 2) , I want to get the line's outline(path), see the Example Image's black line.
In one world, I have wall corner's coordinate, I want to figure out the outline's path of the wall(In the Example image, the red part is the coordinate, and the black lines are what I want to get )
Example Image
I've been working on a similar project. I decided to use vectors to get the parallel lines along the path by getting the cross product of the UP vector and the vector of points 1 to 2 which will get you a vector that is pointing away from the line that you can use to get the begin and end point of the parallel line
CVec3 a, v1, v2, zero, up(0, 1.0f, 0);
zero.set(0,0,0);
v1.sub(points[1], points[0]);
v2.sub(points[2], points[1]);
a.crossProduct(up, v1);
a.normalise();
result[0] = result[1] = a;
result[0].mult(wallwidth).add(points[0]);
result[1].mult(-wallwidth).add(points[0]);
result[2].set(result[0]).add(v1);
result[3].set(result[1]).add(v1);
result[0] to result[2] is line in one side while result[1] to result[3] will be the other one. I haven't figure out how to connect the lines so they make corner without deforming the line width

The crop command of ImageJ does not give correct dimension

I have an image that is 2048*2048. When I run the following macros:
makeRectangle(304, 304, 1450, 1450);
run("Crop");
it then results in an image of 1450*1450. Why not (1450-303)*(1450-303)?
Because makeRectangle expects the x and y coordinates of the upper left corner, as well as the width and height (not the coordinates of the lower right corner) of the rectangular selection.
The line
makeRectangle(304, 304, 1450, 1450);
is equivalent to
run("Specify...", "width=1450 height=1450 x=304 y=304");
(see also the ImageJ user guide)

Select by color doesn't select all the pixels of the desired color in a python-fu script

I am writing a python-fu script for gimp that should have a line where it select all pixels of certain color. To do this, I added the line:
gimp.pdb.gimp_by_color_select(clipLayer,(white_level,white_level,white_level),0,CHANNEL_OP_REPLACE,TRUE,FALSE,0,TRUE)
where cliLayer is the layer I'm working on (top layer) and white_level is an input parameter.
When I give the value manually (e.g replacing the (white_level,white_level,white_level) with (136,136,136)), the selection is carried properly, why is that so?
Adding
white_level = int(white_level)
at the beginning of the function solve this.

How to get a line as a structuring element in openCv?

I have a binary image and I want to perform closing on that image with the line as structuring element.
The openCv api has a function getStructuringElement that takes the following parameters
Shape
Size
Anchor Point
I can pass CV_SHAPE_CUSTOM in the first parameter to create a new shape but where do I
pass the size and the values of my structuring element.
My line will be 10 pixels wide and 1 pixels in length basically {1,1,1,1,1,1,1,1,1,1}.
There is an old function createStructringElementEx but I don't want to use that as it involves a lot of conversion of datatype.
Is this what you want?
Size = Size(10,1)
Anchor Point = Point(-1,-1)
Got it . Thanks to the comment from Niko.
Create a matrix as
Mat line = Mat::ones(1,10,CV_8UC1);
//now apply the morphology close operation
morphologyEx(img, img, MORPH_CLOSE, line,Point(-1,-1));
This solved my problem.

Resources