Parallel lines on polygon or freehand ROI

fiji

#1

HI all,

I recently started using FIJI and I am running a few tutorials I have found around. I’m trying to create multiple vertical (90 degrees) parallel lines on an image as I want to measure the length of an object not completely rectangular (non straight lines on bottom and top) at different points. I have found this useful thread with a macro, but my images differ in that the ROI I will be using is not rectangular (it’s not a perfect rectangle). Is there any way to be able to do this?

Many thanks in advance


#2

Please post a typical raw image in the original TIF- or PNG-format. No JPG-format though, because JPG introduces artifacts! You may also post images as Zip-archives.
(Converting a JPG-compressed image to TIFF- or PNG-format doesn’t make sense.)

Please explain in detail what you like to measure and what’s the role of the vertical lines. (Do you like to get the intensity profiles along the line segments?)

You write that you have a ROI, so you may post an image in TIF-format as ZIP-archive with the ROI as an overlay.

Please be as specific as possible.

Regards

Herbie


#4

Thank you @Herbie ,

This is an example of the image. I drew the black lines on top to better explain it. What I would like to know if it is possible to draw those lines automatically using a macro. The number of lines I used it was random, but it would great to have them separated a certain pixel distance (let’s say 20 or 50 pixel). I only need the length of those lines as I would then compare variation of that length. I need nothing else.


#5

Thanks for the details!

Please read carefully:

Please post a typical raw image in the original TIF- or PNG-format. No JPG-format though, because JPG introduces artifacts! You may also post images as Zip-archives.
(Converting a JPG-compressed image to TIFF- or PNG-format doesn’t make sense.)

We need an image in the original size without any pre-processing and without the lines!

It would be helpful to get the object on a homogeneous background!

Regards

Herbie

PS:
Here is the Object Height as a function of the horizontal object coordinate X:


X and Height are in pixels.
If you make accessible sample images without the lines I may supply an ImageJ macro that creates such plots with numerical values available.


#6

Thanks a lot @Herbie

See if this image works better.


#7

Please no JPG-compressed images for scientific purposes like image naalysis etc.

Reagrds

Herbie


#8

I have been having problems uploading the tiff image so I just copy/pasted it. This is what get when I upload tiff file


#9

Thanks, the image in TIF-format arrived well.

Blue background is perfect!

Results in some minutes!

Regards

Herbie


#10

Thanks a lot for your help!

Regards,
Pnd


#11

Well Pnd,

here is the binarized object from which the object heights are determined

and here is the plot with the object heights:


Again the dimensions are in pixels.
Here is the plot again as ZIP-archive:
objectHeights.zip (5.8 KB)
After unzipping the archive you are to open the file in ImageJ. Click on the “List”-button beneath the plot and you get the numerical values of the object heights.

Here is the ImageJ-macro code that I used:

requires( "1.52h" );
setBatchMode(true);
setOption("BlackBackground", true);
setBackgroundColor(0, 0, 0);
run("Split Channels");
close();
close();
setAutoThreshold("Percentile dark");
run("Convert to Mask");
run("Fill Holes");
run("Analyze Particles...", "size=1000-Infinity pixel add");
run("Remove Overlay");
roiManager("Select", 0);
run("Clear Outside");
run("Crop");
run("Select None");
close("ROI Manager")
w=getWidth();
h=getHeight();
height=newArray(w);
for ( i=0; i<w; i++ ) { 
   makeRectangle(i,0,1,h);
   height[i]=distance(h);
}
run("Select None");
Plot.create("Object Height", "X", "Height", height);
setBatchMode(false);
exit();
//
function distance(hh) {
   setKeyDown("alt");
   p = getProfile();
   setKeyDown("none");
   j=0;
   while (p[j]<1) {j++;}
   top = j;
   p= Array.reverse(p) ;
   j=0;
   while (p[j]<1) {j++;}
   return (hh-j-top);
}

Paste the above macro code to an empty macro window (Plugins >> New >> Macro) and run it with the sample image open in ImageJ.

I can’t predict how this macro generalizes to other images of this kind.
In any case red flesh at object edges may pose problems for the correct binarization because the red image channel is used. You have to decide whether the results are suitable for your purposes. Please report back!

HTH

Herbie


#12

This solution works fine for me. Many thanks @Herbie.

Regards,
Pnd