Segmentation and thresholding

i am want to use the tranable weka segmentation tool on the image given. The problem is i have to use the hand tool to segment the image .However i am trying the segment the black pores , and white grains from each other but due to almost same intesnity of some black region i guess of the image it dsnt work properly i get results but not satisfied.
If some one can give me any idea or macro for it how to do it. so i can have a good segmented image. kindly guide me on below images.

And also for the other image which is 7 days sample

Hello @M.khattak,

I have replaced your TIFF images with PNG so they can be visualized in the forum. Can you please indicicate which are the regions of the image are the black pores you wish to segment? Is hard to guess from a non-expert eye.


Thank you so much for your reply.
Actually the image seen above the white spots are grains and the black spts are voids, Its basically Saccaing electron microscopic image .White spots are shown in those area where the electron repulse back. While the black because of voids in the sample they passes by and i guess hit the background.

Here now i want to calculate the voids ,and grains in these sample images , their number particle analysis and want to calculate the porosity of the voids black spots.For which i want to have a good thershoulding and each sector seperated from each other so it can give me a good idea…

However as you can see in the images the black spots have some thin layer almost same intensity as white and in some region they are very dark which is fine. I want to seperate them and then do several stuff with it,but my thershoulding in this case i guess need to be perfectly fine to do the analysis. which i am having big time issue as i am new to iamge j. These are not only the image i have more 50 60 images to deal with.
Different days sample whos voids number shape changes with time to time.

Could you provide an example of what would be a good segmentation for you? Maybe made manually in a cropped version of the images?


This is SEM image whom before starting segmentation I adjusted the brightness and contrast so it can give me a better black and white regions.And got probability maps for it however doing same for all pics will be hard. if you need any other example image kindly let me know .
thank you so much for the reply.

<img src="//" width="690

" height=“407”>

Hello @M.khattak,[quote=“M.khattak, post:5, topic:5624”]
however doing same for all pics will be hard

It would help if you manage to normalize the intensities of all your input images. That way, a classifier trained on a few images is more likely to work on new images containing similar structures. Have a look at this conversation on how to normalize the brightness and contrast of a set of images.


I visited the page and upto my knowledge I copyied the script and used it and created a histogram however as I am new I didn’t got what else the discussion was about .
I opened the images in stack and run the script . Is that the only step which I need to do with my images I did got intensify images .
Is that the only method I should do before using the weka segmentation. ?
thank you so much for your help looking forward to your response and ideas.

The objective is that your images stay in the same range of intensities (same mean and standard deviation intensity values) so the classifier trained on some of your images works as well for images it has never seen. Any normalization would help. If you have passed the histogram-matching script to a stack of your images, then they should be good to go.

The idea behind is that if you successfully train a model to segment pores of a certain size, shape and intensities, it should work on new images of pores as long as the pores “look” similar. The size and shape depend on your samples, but the intensities can be corrected using this type of techniques.



This is the particle analyser for binary image for pores. However I want to calculate the pore diameter and the porosity of the image and want to plot it in the excel and make a graph of it . An pore diameter on the x axis and porosity on the Y axis.
If you can guide me on how to do that with the current image I posted.

thank you so much for all the help looking forward to it.

Could you use the “Bounding rectangle” option under Set Measurements?

Dear @M.khattak,

for those rather amorphous shapes like your Particle Analyzer outcome the term diameter is kind of relative. Compared to a diameter of a circle which is everywhere the same, where would you define your diameter?
An idea could be the feret’s diameter (can be set under ►Analyze ►Set Measurements…) as the longest distance in your “particles” or the major or minor axes (defined on an ellipse over your particle) as size indicators.

But IMO, one important thing to consider having never done porosity analyses myself, is if it makes sense to deduce a 2D size measurement from an image created by a rather pseudo 3D image output (SEM image displaying 3D structures in a 2D image).
I don’t know how other would see this in this context?

Surely, you can measure those diameters or areas but depending on the view onto your pores or their orientation this will be a very variable output and the question will be if you could reliably compare different sample with small differences in such a way.


I Did apply the bounding rectangle option and got some values. but I donot know how can I interpret the values for the pore diameter. Each polygon or circular pores. For pore diameter I asked my fellow and he said you can assumed all the pores to circular during calculation and make graph with for image showing …
pore diameter with the porosity.
For reference the image is attached .still not sure how I can achieve this .the data obtained is through image j. and than graphs are made.

I agree with @biovoxxel, you might want to use the Feret diameter or the minor/major axis of a fitted elipse.