Home Image-Pro General Discussions

How to approach excluding holes above a set threshold

I am trying to get the size/area of sections of lung tissue. As this tissue essentially looks like a sponge, there are numerous holes (the part of the lung containing air). Many tissue sections also contain large blood vessels that also appear as empty space that I would like to exclude from the area measurement. I guess another way to put it would be to fill holes but only those below a certain size.

As I would like to later eliminate non-lung tissue (by splitting and then excluding the non-lung tissue) it would be preferable to not do the above by creating a mask as it will add the additional step of correlating it with a non-mask image.

The images are extracted from a whole slide scanner so file sizes range from about 50MB to 1GB and I have hundreds of images so processing time is a concern.


Thanks

Ross T

Best Answers

  • Answer ✓
    rtaliano,

    The idea of the processing would be to exclude the unwanted objects (holes in your case) by segmenting and applying them as excluded ROI. Here are the steps how it can be implemented:
    1. Segment only Holes above certain threshold. I've attached the options file (Holes.iqo) that define the threshold and and also filter ranges for "Percent area", which is set >0.06% detecting only large holes and background. I also set the "Grow" option to -1 (Restricted grow is OFF) to close small gaps between lung tissue and use Fill Holes to make solid objects. The result image should contain only objects you want to EXCLUDE:

    You have tweak the filter ranges using other parameters (like Aspect ratio,...) to detect objects by shape. You may also draw objects manually, after the segmentation.

    2. Add these objects to the Features Manager. Then change object type to ROIs and put it back to the image, (delete Count/Size objects). Invert ROIs, clicking the Invert button in the ROIs settings drop-down. Now, the image contains only ROIs that exclude large holes and background:


    3.  Then you can segment the lung tissue (use Auto-dark segmentation with positive Grow), activate Fill Holes if necessary. I've attached the Tissue.iqo that produces this result:

    If necessary, you may use manual split, to separate touching objects.

    These steps can also be recorded into a macro and used in batch processing.

    Yuri


  • Answer ✓
    Ross,

    Did you Inverted ROIs and then executed Count? (That's the right order).
    If it still doesn't help, try to do tests with simple ROI: e.g. draw a Rectangular ROI, invert it and click Count - to see if the objects are segmented inside or outside the rectangle.

    Yuri

  • Answer ✓
    Hi Ross, 

    Thanks for posting a picture. Looking at it, I realized that the approach I described may not work on some images, as the one you posted, as the Holes.opt uses Fill Holes option that prevents segmenting the tissue itself (on your picture there is no green ROI line along the tissue border). So, another step is needed to make it work properly.

    I have created a macro project Lungs.ipx (attached) that does all steps of the segmentation properly. If you use your test image and run SegmentLungs macro from the attached project, you should get this result:


     The macro uses following steps:
    1. Segments the tissue with holes (TissueWithHoles.opt).
    2. Adds these outlines to Features Manager and puts it back as ROIs.
    3. Segments Holes (using Holes.iqo) inside the tissue. Here you can define Filter ranges for Hole sizes. Note, the the Maximum hole size is set as percentage of the Tissue area. The current value is 0.1 (you can adjust it by loading Holes.iqo, changing the limit in Types drop-down and saving it back to Holes.iqo)
    4. The holes measurements are also added to the Features Manager and put back as ROIs (in addition to ROIs with tissue outlines).
    5. The macro sets ROI options to ROI XOR, so  holes are excluded from tissue area.
    6. Finally the tissue area is measured using Tissue2.iqo (the intensity range is set from 0 to 255).

    After this you may use manual split to separate touching tissue areas, if necessary.

    Yuri

Answers

  • 2019-01-07-101604

    Ross --

    There is a saying that "a picture is worth a thousand words!"

    If you will provide an EXAMPLE IMAGE (or an EXAMPLE IMAGE SET) that illustrates the challenge you face we can assist you much better.  If you can provide BEFORE and AFTER or ORIGINAL and PROCESSED versions that would be SUPER.

    Thanks.

    -- Matt

  • Hi Matt,
    Low and high magnification images of a representative area are attached. The areas I want to exclude are the larger, irregular (but smooth contoured) areas. These have not been processed in any way. At the moment I am not in front of the ImagePro computer so I couldn't send those. I think all I would do in terms of preprocessing is to do a close to reduce the number of very small bright areas (holes) that would be counted. The pain in the butt with this project is that in some of these images there is non-lung tissue that I need to exclude, such as that circular reddish structure with the central lumen. It will be hard to split those off in many cases without being able to see them. Thus making a simple mask would make this difficult. In addition, the tumor deposit areas are to be measured manually as well and many of them are quite small. So if the images are too heavily processed the tumor deposits will be tough to locate. One could compare the mask and original images side-by-side and this would seem to be the path of choice for a small number of images. But I have several hundred.

    Thanks in advance
    Ross T
  • I noticed I said "(holes) that would  be counted". I don't need to count those but hope to make processing time shorter by not having those areas identified as holes up front.
  • Yuri, this looks great. I loaded the recipe and tweaked the % and I get the areas I want to exclude. I then added the objects to features manager and changed measurement to ROI. I then put them back onto the image (I can see the outlines) but when I try to segment that resulting image via the tissue.iqo you sent or any sort of dark segmentation I cannot get the lung tissue to be recognized. It only gets objects on the border of the image. Changing the clean border option had no effect. In fact, even if I adjust the threshold so that everything should be selected there is no change. So I must have a setting wrong somewhere.

    Thanks

    Ross


  • 2019-01-08-112741

    Ross --

    It sounds like YURI has provided a path that takes you very close to where you want to be.

    Please find below another path which may be an option.

    The step from CC to DD requires MANUAL SPLITTING but if your images are consistent, I believe that all of the other steps could be automated.

    If this path looks promising, I can provide more info.

    -- Matt






  • rtaliano said:

    Yuri, this looks great. I loaded the recipe and tweaked the % and I get the areas I want to exclude. I then added the objects to features manager and changed measurement to ROI. I then put them back onto the image (I can see the outlines) but when I try to segment that resulting image via the tissue.iqo you sent or any sort of dark segmentation I cannot get the lung tissue to be recognized. It only gets objects on the border of the image. Changing the clean border option had no effect. In fact, even if I adjust the threshold so that everything should be selected there is no change. So I must have a setting wrong somewhere.

    Thanks

    Ross


    Ross,

    It looks like you missed Invert ROIs click.

    Yuri

  • Yuri,

    I clicked on the ROI drop-down and highlight the "invert ROI's but for some reason it still wont work. Any ideas?

  • Yuri, I got it. I believe what was happening was that instead of putting "objects" back onto image I was hitting put "features" back. I am using two screens so the hover text was only partially visible and I didn't notice the two were different.

    I am already to macro and batch but have one additional question. Is it possible to export the data from the analysis of multiple images to one excel sheet. The last time I used the excel export I recall that the analysis of each image in a batch produced a data table for which I included an export into excel. Is there a process to combine the data and export to a single excel spreadsheet?


    Thanks

    Ross


  • Yuri, and also one additional question that one of my colleagues wanted to know. As I mentioned the tissue area is half of the process. The other half will entail one of my colleagues manually measure areas of interest. Is there a way to save that annotated image (with or without the associated data table)?


    Thanks

  • Sorry Yuri, one more. When the objects are added to the features manager, the number of polygons/items is not necessarily the same for different images. As I mentioned above, selecting put features back onto image rather than put OBJECT back on image doesn't appear to work. How then can a macro be written so that all of the objects are put back onto the image if this action cannot be done globally so that images with different numbers of ROI's are handled the same?

    Thanks

    Ross

  • Hi Ross,

    The best way to export data from multiple images to one Excel sheet is to use Data Collector. So, you collect necessary data from every image in a batch macro, and then just export Data Collector table with all results (you can find several posts about Data Collector on this forum).

    Regarding saving annotation. There are several ways:

    1. You can draw image annotation, measurement objects or ROIs right on the image, then just save the image to TIF file and all overlays will be saved too.
    2. You can also use Features Manager for saving any of overlays: add measurement objects to Features Manager and save to *.roi file. Then you can load these files and put features on the image.
    3. If you draw measurement objects, then they can also be saved to a separate file (*.iqm) from Measurements table (Save/Load buttons).

    Yuri

  • Disregard that last question. Clicking on put "collection" back onto image appears to solve that problem.
  • rtaliano said:

    Sorry Yuri, one more. When the objects are added to the features manager, the number of polygons/items is not necessarily the same for different images. As I mentioned above, selecting put features back onto image rather than put OBJECT back on image doesn't appear to work. How then can a macro be written so that all of the objects are put back onto the image if this action cannot be done globally so that images with different numbers of ROI's are handled the same?

    Thanks

    Ross

    I described the workflow where Measurements are added to Features manager and put back to the same image as ROIs. So, these steps should be executed in a macro processing single image. You should clean Features Manager before adding measurement objects there to be sure that you put back the right ROIs.

    Yuri
  • Ross,

    I also don't quite understand what you mean mentioning "put features back onto image rather than put OBJECT". You should just click the "Set Feature to Image" button, next to ROIs selection:



    Yuri 
  • When I try to use set feature the ROI's show up on the image but when I run tissue.iqo that is when I end up with no result (doesn't recognize tissue and is picking up the edges of the background. Notice left upper corner.

    FYI I did raise the threshold for the hole size as it overall works better if I try to getting rid of only the largest of the holes. That is why there are some holes that are not highlighted.


  • Yuri, that is a work of art and crazy fast. I just need to play with the % threshold. It is fascinating to learn how to tweak this. The image here is the macro run on the native TIF file. It is excluding to many areas which I guess is a statistical phenomenon? I noticed it before when I would run a macro on an image like this and then on an image that has twice as much tissue. Depending on the orientation of the tissue there is more or less background due to the size of the bounding box. So a holes of similar size on two different images would be two different % sizes, correct. Totally not a big deal for this project as the goal is to get rid of the large ones. But for future reference...I may play around with it later....what parameters would you include to try to keep the more irregularly shaped regions (which are just some confluent airspaces in the lung tissue rather than gaping blood vessels) from being excluded. I experimented with those that looked to be based more on shape rather than size and had some success but it would appear it will require a combination of filters so I wondered which ones you think would be the most promising?

    Will you guys be running any hands-on training sessions again at your place?


    Thanks

    Ross

  • Ross,

    Currently, the % threshold is set for "Percent Area %" measure, so you may get different results on images at different magnifications and also with different tissue area. The proper way to handle the threshold would be to set it for "Area" in calibrated units. That would require applying proper spatial calibration to the image before running the macro (your original image was in JPG format and didn't have calibration). So, you should consider creating calibrations for your images and changing Holes.iqo to use filter by "Area" (area of the smallest hole to exclude).

    Live trainings will be posted on this page http://www.mediacy.com/company/events , you can also send such question on our website or register in advance here http://www.mediacy.com/trainingregistration .

    Yuri 
  • In the process of trying to tweak the %area I have managed to lose the script somehow. I searched the forums and user guide but I am not clear on how to properly place the ipx file. I removed the project and via Open Project on the App ribbon I opened the ipx file again. It tells me that it wants to overwrite the scripts Holes.iqo, Tissue2, etc. The project shows up with the lungs module but there is no script/macro to run.
  • Hi Ross,

    The Lungs.ipx is attached to my earlier post (it was moved to the top when you marked it as Answered). You can re-download it again. (keep the original copy in a safe place). And yes, when you load it, it may ask to overwrite the files, you may say No, if you already modified some options files.

    Yuri
  • I redownloaded and via the Open Project I opened the ipx and verified that the files (Holes.iqo, IntensityCalibrations.iqi, SpatialCalibrations.iqc, Tissue2.iqo, and TissueWithHoles.iqo are present in the configuration files. A "Lungs" project and module appear but there is no script of any kind within the module. How do I get the macro/script to show up?


    Ross

  • You shouldn't do anything to show up the Module (besides expanding the tree node).
    I just downloaded the IPX from this post and it looks correct. Maybe you are loading an old/corrupted IPX or a cached version. 
    Try to  Remove Lungs project from the list of projects (use Remove Project from Context menu), restart Image-Pro and load the correct IPX clicking the Open Project button on the Apps tab.

    Yuri

Sign In or Register to comment.