Chest X-Ray Segmentation


Second post here… I am working with pretty heavy chest X-ray dicoms. My issue is with the segmentation of lung region. I want to select lungs as ROI and create mask for one image. I want to batch implement this process to the rest of my mages. Is there a way to create a macro that enables lung region to be selected for each image and then mask created based on that?

My issue is the size of my images. I was interested in doing Weka, but it doesn’t work for the size of my images. Will Nifti conversion help?

Also, I want to try the Ilastik voxel segmentation. It doesn’t appear on the 1.4 version. Does anyone know how to activate it?

Thanks in advance…


Hey @maria1,

How large are your images? Can you share one? Furthermore, for segmenting the lung as one big region of interest (or two: left/right) full spatial resolution might not be necessary. You can try to process it with reduced resolution (Image > Scale…)

If you want to process voxels: Are we talking about X-Ray imaging or CT imaging? If you do CT imaging, lung segmentation should be doable with some thresholding + postprocessing, because CT images use the Hounsfield scale… No real need for machine learning… Did you consider that?

Let us know what you think.


Hey, thank you for the response. Apologies, can’t share the image; data privacy issues. They dont appear too heavy, as one I just checked is just 12 mb. But when training with WEKA segmentation, I run out of memory, even with 10GB allocated to the process. I am trying with reduced resolution to see if it works, after reading your post; but my project aim is to ensure no lossy compression takes place.

My images are X-Rays. Ilastik does seem to work, what with no memory issues… but will any f these processes work as batch?

I hope I’m making sense…

You reduce the image just for segmentation. You can upscale the result afterwards and analyse the lung region in original resolution.

Let us know if it works :slightly_smiling_face:

thanks, will do…

I wont be able to save a dicom file in the same format, would I? Dicoms are not writable in ImageJ, … no?

Hi @maria1,

I agree with @haesleinhuepf that you could downscale your image for segmentation. But 12 mb doesn’t sound large at all, what is the size in pixels of your image.

If you’d want to get down the ilastik route I’d recommend exporting your dicom to hdf5 using the ilastik import/export plugin in fiji and go to ilastik with this image.

Once you have trained a classifier on a few images you can batch process ilastik directly from within fiji.

The Voxel segmentation workflow is not active per default at the moment. We haven’t found a use case where it would be better than pixel classification (or autocontext) and it’s much slower. So right now we don’t recommend to use it. In order to “activate” it, you’d have to start ilastik from the command line passing the --hbp flag. Still, I’d advice against it at the moment in favor of trying the pixel classification workflow and/or the autocontext workflow.

Hi, thank you for helping with this. So, I just finished seg in Ilastik over an image and batch processed it onto 4 more. I am now saving them in HDF5 format. I tried batch processing from within ImageJ, and it throws an armada of exceptions and errors.

How does the batch get saved up in the HDF5 format? Is it a map for each image? Apologies for the questions… all greek to me…

Another question that popped into my mind… Ilastik would only batch process mages that have the same type and size. Whats the best way to resize images as per one standard image and ensure ROIs, lungs in my case don’t get cropped?


Hi @maria1,

as for the armada of exceptions and errors, have you first configured the ilastik executable? It’s also in the plugin menu and from the log you posted it looks like it’s applying some default setting…

So if we’re talking about batch-processing via the batch processing applet in ilastik, a problem that often occurs is that it’s only one file that is written, no matter how many input files are added to the batch processing list.

If you’re going via the batch processing route, you have to make sure your export settings are configured using our “magic placeholders”. We have some documentation here, look under “Output File Info”. The most important one in this case is {nickname}. It will automatically derive a file-name from your input file (usually the input file name). So if those are diffferent, you’ll get a new file for every input file.

Hey, thanks so much for this.

How does Ilastik work with multiple seperate image input? Does that mean training for teh ROI with several images, and giving the model a better chance to identify the region of interest?

Hi @maria1,

ilastik combines the information from all images you add to a single pixel classification project. So, yes, there is a better chance for the model to generalize if you support more images. This of course comes with some downsides. If you add more than 10, 20 images it might get noticeably slower :confused:
How are your results so far? :slight_smile:

Hi, thanks. The first time I tried, it worked quite well. I could open it in ImageJ and apply other plugins. This time around, it seems to be opening differently, with a scroll bar at the bottom and not displaying anything (I adjusted the contrast). I will try it again today to see what I did differently the first time that it worked. Its probably the format I am saving or opening it in. This time I saved in the HDF5 format.

I keep on adding more questions to this thread, sorry; I have a few more: my question is with regards to the labels in Ilastik. The labels 1 and 2 become segmentation 1 and 2, respectively. My ROI is segmentation 1. Is seg 1 selected as the ROI by default? Also, I see there are crop options in both Ilastik and ImageJ. I am a little concerned about using them as my aim is to use batch processes, and every image is different, so crop might not be uniform. Can I possibly crop it to include segmentation 1?

Also, with regards to ImageJ, I applied CLAHE to my image just on the lung area through a mask. This was a pretty cool effect. Whats the best way of batch processing this process?

@k-dominik and @haesleinhuepf you’ve been a huge help, thank you…

1 Like

I find that most medical students select far too any pixels for each region selected. They just swipe away like crazy assuming that more data is better.
Try selecting fewer neighboring pixels and you may not run into a memory problem while getting a good segmentation. If there is a background gradient, try removing it first, before TWS.

Actually, I tried both ways with X-Ray images. The tricky part is the lung region, which looks a bit like the heart, other segments look like the bone structure around and even the outer shell. I found swiping a lot better than just drawing a few lines here and there. But lesser layers definitely work better. I have only two or three.

Hi there, not sure if this question is still open, but you can perform Deep Learning assited lung segmentation. Here are a couple of models:

Hope this helps :wink: