Multi ROIs analysis / ROIs saving as .jpg

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Multi ROIs analysis / ROIs saving as .jpg

dgxn88
Dear all,

I need to automatize the measurement of the length and yolk sac area of fish larvae which have been scanned in 12-well plates. The plates were always positioned at the very same place on the scanner, allowing for a selection of ROIs that applies to every images. I've came up with the following 2 options:

1) Make a macro that select the ROIs, calls another macro that run the particle analysis for the yolk sack area for every ROIs

2) Make a macro that select the ROIs an save these ROIs as .jpg. Use an other macro that batch process the particle analysis of the folder containing the ROIs as .jpg.

Considering my limited skills in programming in ImageJ, I've opted for the second option. The code I wrote so far is:

roiManager("reset")

// this select ROI of the top plate

makeOval(1520, 80, 560, 560)
roiManager("Add")
makeOval(2130, 80, 560, 560)
roiManager("Add")
makeOval(2740, 80, 560, 560)
roiManager("Add")
makeOval(3350, 80, 560, 560)
roiManager("Add")

makeOval(1520, 690, 560, 560)
roiManager("Add")
makeOval(2130, 690, 560, 560)
roiManager("Add")
makeOval(2740, 690, 560, 560)
roiManager("Add")
makeOval(3350, 690, 560, 560)
roiManager("Add")

makeOval(1520, 1300, 560, 560)
roiManager("Add")
makeOval(2130, 1300, 560, 560)
roiManager("Add")
makeOval(2740, 1300, 560, 560)
roiManager("Add")
makeOval(3350, 1300, 560, 560)
roiManager("Add")

//this select ROI in the middle plate

makeOval(1520, 2100, 560, 560)
roiManager("Add")
makeOval(2130, 2100, 560, 560)
roiManager("Add")
makeOval(2740, 2100, 560, 560)
roiManager("Add")
makeOval(3350, 2100, 560, 560)
roiManager("Add")

makeOval(1520, 2710, 560, 560)
roiManager("Add")
makeOval(2130, 2710, 560, 560)
roiManager("Add")
makeOval(2740, 2710, 560, 560)
roiManager("Add")
makeOval(3350, 2710, 560, 560)
roiManager("Add")

makeOval(1520, 3320, 560, 560)
roiManager("Add")
makeOval(2130, 3320, 560, 560)
roiManager("Add")
makeOval(2740, 3320, 560, 560)
roiManager("Add")
makeOval(3350, 3320, 560, 560)
roiManager("Add")

//this select ROI of the bottom plate

makeOval(1520, 4120, 560, 560)
roiManager("Add")
makeOval(2130, 4120, 560, 560)
roiManager("Add")
makeOval(2740, 4120, 560, 560)
roiManager("Add")
makeOval(3350, 4120, 560, 560)
roiManager("Add")

makeOval(1520, 4730, 560, 560)
roiManager("Add")
makeOval(2130, 4730, 560, 560)
roiManager("Add")
makeOval(2740, 4730, 560, 560)
roiManager("Add")
makeOval(3350, 4730, 560, 560)
roiManager("Add")

makeOval(1520, 5340, 560, 560)
roiManager("Add")
makeOval(2130, 5340, 560, 560)
roiManager("Add")
makeOval(2740, 5340, 560, 560)
roiManager("Add")
makeOval(3350, 5340, 560, 560)
roiManager("Add")

//this will rename the ROIs with the well IDs

roiManager("Select", 0)
roiManager("Rename", "1-A4")
roiManager("Select", 1)
roiManager("Rename", "1-A3")
roiManager("Select", 2)
roiManager("Rename", "1-A2")
roiManager("Select", 3)
roiManager("Rename", "1-A1")
roiManager("Select", 4)
roiManager("Rename", "1-B4")
roiManager("Select", 5)
roiManager("Rename", "1-B3")
roiManager("Select", 6)
roiManager("Rename", "1-B2")
roiManager("Select", 7)
roiManager("Rename", "1-B1")
roiManager("Select", 8)
roiManager("Rename", "1-C4")
roiManager("Select", 9)
roiManager("Rename", "1-C3")
roiManager("Select", 10)
roiManager("Rename", "1-C2")
roiManager("Select", 11)
roiManager("Rename", "1-C1")

roiManager("Select", 12)
roiManager("Rename", "2-A4")
roiManager("Select", 13)
roiManager("Rename", "2-A3")
roiManager("Select", 14)
roiManager("Rename", "2-A2")
roiManager("Select", 15)
roiManager("Rename", "2-A1")
roiManager("Select", 16)
roiManager("Rename", "2-B4")
roiManager("Select", 17)
roiManager("Rename", "2-B3")
roiManager("Select", 18)
roiManager("Rename", "2-B2")
roiManager("Select", 19)
roiManager("Rename", "2-B1")
roiManager("Select", 20)
roiManager("Rename", "2-C4")
roiManager("Select", 21)
roiManager("Rename", "2-C3")
roiManager("Select", 22)
roiManager("Rename", "2-C2")
roiManager("Select", 23)
roiManager("Rename", "2-C1")

roiManager("Select", 24)
roiManager("Rename", "3-A4")
roiManager("Select", 25)
roiManager("Rename", "3-A3")
roiManager("Select", 26)
roiManager("Rename", "3-A2")
roiManager("Select", 27)
roiManager("Rename", "3-A1")
roiManager("Select", 28)
roiManager("Rename", "3-B4")
roiManager("Select", 29)
roiManager("Rename", "3-B3")
roiManager("Select", 30)
roiManager("Rename", "3-B2")
roiManager("Select", 31)
roiManager("Rename", "3-B1")
roiManager("Select", 32)
roiManager("Rename", "3-C4")
roiManager("Select", 33)
roiManager("Rename", "3-C3")
roiManager("Select", 34)
roiManager("Rename", "3-C2")
roiManager("Select", 35)
roiManager("Rename", "3-C1")

//this will save the ROIs as .jpeg

n = roiManager("count");
 for (i=0; i<n; i++) {
        roiManager("select", i);
        run("Duplicate...");
        saveAs("Jpeg");
        close();
  }
  </i>

I'm quite close to achieve the second option except that I still need to click. I would like that the last part saves the ROIs as .jpeg with the ROI's name (eg. 1-C4) and in a specified folder (ideally the folder which contains the scan).

If you have any suggestion or if you know how to go for the first option, I'd be more than thankful. The sample size is about 10K larvae so the need to automatize the procedure is particularly high.

Best,
David
Reply | Threaded
Open this post in threaded view
|

Re: Multi ROIs analysis / ROIs saving as .jpg

Olivier Burri
Dear David,

I have written a small piece of code to help you in achieving option 1
https://gist.github.com/lacan/348ff4267addfcf99487

If you run this, you will see that it is producing the same ROIs as you, just using for loops, so in case the imaging conditions change slightly, you can update the code as needed, rather than redrawing all the circles.

Secondly if you scroll all the way to the end, there is a short loop that will iterate through all the ROIs and run a function called runAnalysis.

In this function (line 49), you can add the macro commands that you use to measure a single yolk sac. The nice thing in imageJ is that once you have a selection made, Analyse Particles will only return objects found inside the area enclosed by that selection.

Hope this helps

Best

Oli

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Multi ROIs analysis / ROIs saving as .jpg

dgxn88
Dear Olivier,

Thanks a lot for this solution! However, the code you wrote works fine for plate A and B but not for plate C. For this one, the ROIs are shifted half a well downward. I tried to find where the mistake is, but the only pixel information I can find in your code is at the beginning and every thing looks fine.


Thanks again,
Cheers
__________________________________________
Nusbaumer David, PhD student
UNIL- Biophore
Office 3223
+4121 692 4249
DEE - Department of ecology & evolution
CH - 1015 Lausanne








Le 24 juil. 2015 à 15:29, Olivier Burri [via ImageJ] <[hidden email]> a écrit :

Dear David,

I have written a small piece of code to help you in achieving option 1
https://gist.github.com/lacan/348ff4267addfcf99487

If you run this, you will see that it is producing the same ROIs as you, just using for loops, so in case the imaging conditions change slightly, you can update the code as needed, rather than redrawing all the circles.

Secondly if you scroll all the way to the end, there is a short loop that will iterate through all the ROIs and run a function called runAnalysis.

In this function (line 49), you can add the macro commands that you use to measure a single yolk sac. The nice thing in imageJ is that once you have a selection made, Analyse Particles will only return objects found inside the area enclosed by that selection.

Hope this helps

Best

Oli

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html



If you reply to this email, your message will be added to the discussion below:
http://imagej.1557.x6.nabble.com/Multi-ROIs-analysis-ROIs-saving-as-jpg-tp5013731p5013734.html
To unsubscribe from Multi ROIs analysis / ROIs saving as .jpg, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: Multi ROIs analysis / ROIs saving as .jpg

Olivier Burri
Hi David,

> Thanks a lot for this solution! However, the code you wrote works fine for
> plate A and B but not for plate C. For this one, the ROIs are shifted half a well
> downward. I tried to find where the mistake is, but the only pixel information
> I can find in your code is at the beginning and every thing looks fine.

Indeed, this has now been fixed. You can get the code again at the same link
And you can see what I modified here
https://gist.github.com/lacan/348ff4267addfcf99487/revisions?diff=split 


Best

Oli

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html