Using imageJ to measure areas undergoing corrosion

I have a colored image of a part that has undergone corrosion. I am trying to find a way to measure the area fraction of the part that has undergone corrosion. One way of course is to trace the corroded regions manually and measure the sum of their individual area fractions. However, this is a very tedious method. Is there a way imageJ can do this in an automated fashion?

Here is a sample of the image.


Welcome to the Forum!

Would you be able to indicate what are corroded parts of this pipe? The greenish areas and/or the white areas?

You can take a first stab at this I think with the Trainable Weka Segmentation plugin - a great tool for segmentation that comes directly with Fiji~.

I cropped a piece of your image out and trained a classifier using the default settings… 3 classes - one for the background, pipe, and corrosion. This is the segmentation I got:

There are definitely improvements that could be made if you take the time to study this plugin and the various training features to apply… This classifier that you train can then be applied to other images - as long as you have consistent acquisition conditions/background/illumination/etc. It should get you the masks you need. :slight_smile:

~NOTE: Fiji is Just ImageJ - it is simply a distribution of ImageJ that comes with a bunch of plugins bundled - ready for you to use out-of-the-box. If you are just getting started, we recommend downloading/using Fiji.

eta :slight_smile:



Thanks for the reply. Yes the corroded areas are both the green and the white regions.
I will try FIJI too. Thanks for the recommendation.

The segmentation you have got is excellent. Way better than I would need actually.
I am trying to learn the tool myself now. New to image analysis and ImageJ. During training, my computer keeps freezing. Probably using too much processing power? By the way, what I really need is the area fraction of the corroded region. In other words I am looking for [number of pixels in the red region/(number of pixels in the red region+number of pixels in the green region). Is there a way to get that?


1 Like


So… here are some helpful links for starting with ImageJ/Fiji:

You should focus on the last two … those on Segmentation. That workshop actually goes over an intro into using the Trainable Weka Segmentation(TWS) plugin I used above - should help getting started.

So - I had to crop the image myself to get the TWS plugin to run without error. I am not sure the best way to go about this… if you only need that much processing power to train a classifier - just using cropped parts of some images or using less features - and then once you have the classifier you’re happy with, you can apply it more easily to the full-sized images after? @iarganda - the developer of this plugin - perhaps can give more input on this.

But yes - you can generate probability maps from this plugin and then use those to create binary masks … and then you can do the measurements you need. Again - look at the Segmentation workshop/slides… that will get you started.

If you have more questions - be sure to post again! But this should be enough to at least get you started down the right path…

eta :slight_smile:

1 Like

This is all great info. Just went through the modules on Segmentation you had pointed out and gave the plugin a try. First tried a cropped image and the results I got were pretty decent, comparable to what you had got. Next, tried running the same training for the actual image, and it took almost an hour for it to run before it ended with an error “Out of Memory”. :frowning:

For my project, cropped images would not work. So I plan to give it another shot in the evening.
Also, need to play with the plots and the other features to calculate the pixel fraction.

BTW, Here is the image that I obtained. Its not perfect, but still…


I think you only need to crop the images when you are in the process of training a classifier… that is what is eating up so much memory, etc. You should try to save/apply classifier to a full-sized image and see the time it takes to create a result. That part should be ‘fast’. So just train on different images - different crops - until you are happy with the segmentation… then it should be smooth from there…


Hello @anshul.godha,

Adding to what @etadobson already told you, it seems your image could be easily segmented using only color. So you might also try the SIOX plugin:

Regarding the use of memory of the Trainable Weka Segmentation, it could be very heavy when working with color images and many features. In your case, you can have reasonable results using just a couple of features. Look what I got:

With these settings:


@iarganda, I tried it the way you suggested with just the Gaussian Blur and it worked much faster. It was able to complete the training in about 10 minutes and the segmented image looked really good. But after I saved the classifier and tried it on another image, I got an error after about 10 minutes of processing.

I will try using the SIOX plugin tomorrow morning. However, even if that works, I am still looking for a way to count the fraction of pixels in a particular color range. In your Weka image, that would be ratio of Green pixels and (Green + Purple) pixels. Any suggestions on how to do that? I have tried using the Color Inspector 3D plugin that looks promising so far.

This is very strange. I tried on my machine and it worked fine. Can you tell me step by step what you did?

First of all, notice the image is not a real color image (RGB) but an 8-bit (grayscale) image with a specific color representation (Look up table or LUT). The red, green and purple areas correspond to 0, 1 and 2 intensity values. So no color plugin would work on an image like that unless you convert it first to RGB. That being said, have a look at this post on how to quantify the output of TWS.

@iarganda, Thanks for the macro. That did the trick. Big help. Made some changes to it to get the output in a format that I would like. I also realized that if I reduce the size of the image, the classification becomes much faster. .

@etadobson, Thanks to you for getting me familiar with Weka and getting me in touch with @iarganda.

It was good to learn ImageJ and its some of its features over the last few days. It can be a very useful tool. Will try to use it more often. First thing I need to figure out is getting it to do batch processing. All in good time.





Glad you found the help you needed. :slight_smile:

For Batch Processing… there are multiple ways to do this:

  1. ‘Easy’ option using the built in Batch Process window…
  2. ‘Flexible’ option that uses the following script (see below):

In either case - you want to take advantage of the Recorder, which records the actions you take in ImageJ/Fiji into code - it’s the starting point of starting to script in ImageJ/Fiji…

// @File(label = "Input directory", style = "directory") input
// @File(label = "Output directory", style = "directory") output
// @String(label = "File suffix", value = ".tif") suffix

 * Macro template to process multiple images in a folder

// See also for a version of this code
// in the Python scripting language.


// function to scan folders/subfolders/files to find files with correct suffix
function processFolder(input) {
	list = getFileList(input);
	list = Array.sort(list);
	for (i = 0; i < list.length; i++) {
		if(File.isDirectory(input + File.separator + list[i]))
			processFolder(input + File.separator + list[i]);
		if(endsWith(list[i], suffix))
			processFile(input, output, list[i]);

function processFile(input, output, file) {
	// Do the processing here by adding your own code.
	// Leave the print statements until things work, then remove them.
	print("Processing: " + input + File.separator + file);
	print("Saving to: " + output);

Here are some other helpful links…

Hope this helps!

eta :slight_smile: