# How to detect bright thick fibers around boundary?

I need to extract bright thick fibers that are surrounding the cell. In this image:

The bright thick fiber that I am talking is:

I need to find if that exists, and if yes what is the length of that structure or what proportion of perimeter is that structure and how thick it is. This structure in biology is called cell lamellopodia.
I need to do it automated in the macro as I have many images.

Hi @Zeynab,

I’ll give you a lead on how to solve this, rather than writing out the macro. In your other question you already have a selection that delineates the cell. Maybe you have put it in manually, maybe you have, given its name, automatically obtained it by separating the cell from the background. Whichever way, if you set the width of this selection to the expected width of the surrounding, then do Edit>Selection>Straighten, you will obtain an image with the outline stretched. As the Selection>Properties… Width gives a symmetrically widened line, your bright area will either be in the top half or in the bottom half of the straightened image.

Make a duplicate (Image>Duplicate…) while the image while the polygon (not poly line as I wrote before) contour is active, you will need it later.

Currently you have a closed contour (polyline) while you need a line selection for Edit>Selection>Straighten… So by obtaining the coordinates of the selection (Roi.getCoordinates(xpoints, ypoints)) you can then remove any consecutive points touching the image edge, set the selection type to line, create a polyline using the remaining coordinates and straighten the remaining part of the outline.

As you know where the cell is, you can measure its average intensity. You can also obtain the average intensity of the straightened edge. Comparing them will tell you if there is a bright edge present or not.

From there, you can then separate the inner from the outer part of the cell using the duplicate you have made before. The inner part will have the thin fibres left, giving you a better chance at automatically thresholding these, as compared to when the thick border is still present.

1 Like

Thanks. So you said first I need to do Edit>Selection>Straighten then make a duplicate (Image>Duplicate…) and then find average intensity?
The procedure is not clear. Why do I need to straighten? by straightening I would have a polyline which is not the shape of the cell anymore.
How to find the segment that is brighter? You mentioned about the average intensity but how can I find the localization of that? which part of the image with which width? and length?

I was wrong; make a duplicate while the polygon selection is active. I have changed my post.

Why do you need to straighten?
If you straighten, you will get a rectangular new window that contains the pixels of the border selection, but now the upper half of the new image contains pixels originating from outside the cel and the bottom half contains pixels originating from the border of the cell inward. So if you measure the average intensity of the border of the straightened border, which is easy to select, you get the average intensity of the area that may contain the thick fibers (?). In the remainder of the procedure, you measure the average intensity of the entire cell, except for that border area. If the former is higher, your bright border is present, otherwise it is absent.

Another method, which is possible if you have the particular example you show, is to make the selection around the edge, shrink it by 10 pixels and band it by 15 to 20 pixels.
If the second measurement is higher, you have a bright rim.

``````run("Paste");//from system clipboard containing your image
run("Clear Results");
run("Set Measurements...", "mean limit redirect=None decimal=0");
run("RGB Stack");
run("Stack to Images");
run("Tile");
selectWindow("Blue");close();
selectWindow("Red");close();
selectWindow("Green");
setAutoThreshold("Huang dark");
doWand(44, 53);
run("Measure");
run("Enlarge...", "enlarge=-10");
run("Make Band...", "band=10");
run("Measure");
delta = 2;
myNresults=nResults;
cellValue = getResult("Mean",0);
rimValue = getResult("Mean",1);
if(rimValue> (cellValue+delta)){//despite displaying first result as 1, array is 0 based
print("rim visible");
}else{
print("no rim visible");
}
``````
1 Like

Try this on a few of your images to see if the variability in your images break it.

Let me know if the discontinuous selection is a problem.

Ron

(Attachment Fiber Finder Macro.ijm is missing)

//Fiber Finder Macro ron_despain@hotmail.com
oit = getTitle();
makePoint(1, 1, “small yellow hybrid”);
run(“Level Sets”, “method=[Active Contours] use_fast_marching use_level_sets grey_value_threshold=40 distance_threshold=0.50 advection=2.20 propagation=5 curvature=1 grayscale=255 convergence=0.0050 region=outside”);
selectWindow(“Segmentation of “+oit);
run(“Analyze Particles…”, " circularity=0.00-0.50 show=[Bare Outlines] display exclude clear include add”);
roiManager(“Show All without labels”);
run(“Select All”);
run(“Copy”);
selectWindow(oit);
run(“Paste”);
roiManager(“Show All”);
close(”\Others");
close(“Results”);
close(“Log”);
roiManager(“Set Color”, “red”);
roiManager(“Set Line Width”, 1);
run(“Flatten”);
run(“Close”);
selectWindow(oit);
selectWindow(“ROI Manager”);
run(“Close”);
setTool(“zoom”);
exit();
//Macro End

1 Like

@rondespain
Thanks for the help. Does it measure the ratio of those bright fibers to whole perimeter and thickness of fibers?
I dont see any measuring in the code.

@eljonco
Thanks.
Straightening makes a straighten line not a rectangle. Isn’t it?
I dont understand what you mean by banding in “band it by 15 to 20 pixels” .
Is imagej able to shrink (or scale down) with pixels?

Hi Zeynab,

Straightening a one-pixel wide segmented line selection will indeed generate a straight line. Or, rather, a one-pixel high window with a width of the length of the line.

A (segmented) line that has a certain width however will generate, once straightened, a rectangle the width of the line length and the height of the line width. You can set the line width using either a double-click on the line tool, or using Edit>Selection>Properties. Open your sample image and run this bit of code to see it happen:

``````makeLine(12,97,1,48,11,29,48,17,77,18,129,40,128,82,97,97);
run("Properties... ", "name=wideline width=20");
run("Straighten...");
``````

Likewise, if you have a closed ROI (a freehand ROI, a polygon etc), you can make a ‘band’ around that contour. Try the bit of code in the third post of this thread, step through the code and see how the ‘Make Band…’ command creates a band around the segmented cell. As Band only wants to select a part OUTWARD, you first need to move INWARD using the Enlarge with a negative number.

Imagej insets a ROI (which is probably what you mean with ‘shrink’) using the command Edit>Selection>Enlarge if you give a negative argument. That is also in the above code of the third item in this thread.

I kindly ask you to single-step this macro (Copy the code, then in ImageJ do Plugins>New>Macro, paste the code, debug using Debug in ImageJ1, followed by Debug Macro, then repeatedly Step; I think we went through that routine before).

1 Like

The Ridge Detection plugin looks like just what you want.

Ron

1 Like