How to do Batch processing on SEM Image for Different Threshold Value?

fiji
bonej
imagej
plugin
batch-processing
macro
imagej2

#1

Hello,
Good Morning to All,

I want to do batch processing on scanning electron microscopy image at different threshold value to identified Porosity of Petrography SEM Image.
what is the Macro coding for that type batch processing ?

SEM Image :-

Macro Code :-

selectWindow(“SEM1.tif”);
run(“Duplicate…”, " ");
run(“8-bit”);
run(“Threshold Image”, “threshold=70 current”);
run(“Open”);
setOption(“BlackBackground”, true);
run(“Dilate”);
run(“Close-”);
run(“Invert”);
run(“Area/Volume fraction”, “inputimage=net.imagej.ImgPlus@3409178e”);

At this above code I want to do batch-processing with this single SEM image only change in Threshold value :- 0 to 180 and further procedure is same.
if this above change happen then Output Table (Gives Area ratio at different threshold value):-
Result%20Table

I would really appreciate it if anyone can give answers !
Thank you for consideration !

Sincerely,
Shubham


#2

I think you want to add a for loop to your macro, where you increment the threshold value.

Read this


#3

You can also add an entry to the Results table recording the threshold value used to get each result, so you are not guessing later on. See setResult("Column", row, value), on the macro functions reference page.


#4

Hello , Yempski
sorry for let reply.

Introduction to Macro Programming was use full but I can’t found proper step to make batch processing in macro code…

Any more plugin available ?

Thanks
Shubham


#5

Hello , Michael Doube

Thanks for clearing result table confusion by

Shubham


#6

Hi @Shubh94

Have you tried to add a FOR loop to your macro, or was that the wrong idea?

Yempski


#7

Hey,

I was applying FOR loop to this code

for (i = 0; i <= 180; i++) {
run(“Threshold Image”, “threshold=i”);
run(“Invert”);
run(“Area/Volume fraction”, “inputimage=net.imagej.ImgPlus@7e9f5631”);
}

But could not got the incremental part of “i” in loop and also result table shown like this

it’s showing process only for value of i=0 and repeating upto 180 but not increasing in threshold value.

please suggest me better Macro code and help out to correction !

Regards
Shubham


#8
  1. Having the i inside the quotes is probably part of the problem. Try “threshold=” + I

  2. You will need to restore the image, or avoid the invert step before the next iteration.

  3. Not sure about the inputimage parameter. Can you leave it out ?


#9

Hello, Yempski
Sorry to reply you late busy with schedule and have less time for personal project work.

Yes, I have try step 1.

Applying this code…

for (i = 0; i <= 6; i++) {
run(“Threshold Image”, “threshold=” +i);
run(“Invert”);
run(“Area/Volume fraction”, “inputimage=net.imagej.ImgPlus@7e9f5631”);
}

and this result i got…

It’s running only for i=0 not increasing upto i=6 threshold value.

Regards,
Shubham


#10

Hey,

If I am going to apply step 2.

then also i got same output like this image i got six time with i=0 Threshold value
Capture1.tif (1.2 MB)

and result table show only 1 output

Thresholding result for image "SEM1-1.tif
Pore area =0.0036580073160146316
Total area =19.046438092876183
Area ratio =1.9205729166666666E-4

so please suggest me with better code to improve output.

Regards,
Shubham


#11

Hey, Yempski

Step 3. About Input Image Parameter
It is Scanning Electron Microscope Image of Shale.
Attachment : SEM1-1.tif (1.2 MB)

Image Specification : 5.04*3.78 inches, 8-bit, 1.2MB and TIFF file

I want to calculate SEM Image porosity with different Threshold value by applying same morphological operation and want result table.
This is code :

for (i = 0; i <= 180; i++) {
run(“Threshold Image”, “threshold=0 to 180 current”);
run(“Open”);
setOption(“BlackBackground”, true);
run(“Dilate”);
run(“Close-”);
run(“Invert”);
run(“Area/Volume fraction”, “inputimage=net.imagej.ImgPlus@3409178e”);
}

End of output get BoneJ Result table with different Area Ratio.

Please give me any other suggestion to improve batch process code for better output because I am Petroleum Engineer And I don’t know more about Macro coding Language.
I only known with Petroleum Geology Parameter.

Regards,
Shubham


#12

Good Afternoon to all,

For Batch processing on SEM Image
SEM1-1.tif (1.2 MB)

I was applying Macro Code

for (i = 0; i <= 180; i++) {
run(“Threshold Image”, “threshold=” + i);
run(“Invert”);
run(“Area/Volume fraction”, “inputimage=net.imagej.ImgPlus@661c2266”);
close();
}

And Get solution which I want but Now I want more Improvement in code
In Threshold value between 0 to 180 I want only Even number increment in “i” value so how to improve it ?
And also how that macro code add into Plugin ?

Thank you for all of Consideration !

Sincerely,
Shubham


#13

Hi Shubham,

I can help you with the first question: If I understood you correctly you want even increments between 0 and 180, so 0,2,4,6,…,178,180. Right?

If this is the case, I believe you can change the line
for (i = 0; i <= 180; i++) {
to
for (i = 0; i <= 180; i=i+2) {
to achieve your goal.

Best,
Alessandro


#14

Hi @Shubh94,

I was thinking you probably need to decrement the threshold value to get the result you need, but there is an obvious easy solution.

All you need is Analyze>Histogram (ctrl+H) and then save the list. Then just integrate/sum the results and take whatever ratios you need.

Does that work for you?


#15

Hello, Alessandro

I got result as i wish by applying

Thank you for your consideration !

Sincerely,
Shubham


#16

Hi @yempski

It is on histogram analysis at different SEM radiation value but I want to calculate Porosity (Pore space) in Rock SEM Image.
I got that type solution with this code and Excel analysis.

Macro code :

for (i=0; i <= 180; i=i+2) {
run(“Threshold Image”, “threshold=” + i);
run(“Invert”);
run(“Area/Volume fraction”, “inputimage=net.imagej.ImgPlus@661c2266”);
close();
}

Bone_J Result with Excel show sheet :
SEM1.pdf (65.2 KB)

and at last analysis graph with give tangent threshold value for Particle size Analyzer and defined different petrophysical properties.

Is there any plugin to establish petrophysical parameter (Porosity, Pore Space Diameter, Pore throat radius calculation ) ?

Thank you for your consideration.

Sincerely,
Shubham


#17

Hello,
Good Morning to all,

Thank you for everyone consideration to get solution in Batch Processing.

Sincerely,
Shubham