Home Image-Pro Plus General Discussions

Background Correction in Image Pro Plus

Hi all!

I have been having issues with thresholding transmitted light microscope images of opaque particles.  The thresholding works great when there are a lot of particles in the field of view.  However, when there are only a couple to none, it tends to threshold the imperfection of the illumination from the microscope lamp.  Then when the image is counted and measured the program finds particles that are not there due to the lighting.  I have attached images to demonstrate my issue.  The first way I tried to fix this was writing code to set a manual threshold limit, since these are grayscale images I set it to a certain value, but I am worried it may add bias to my data if not all images threshold at that value (causing some particles to be under or over measured).  I have tried to use background correction, and it removes the uneven illumination, but then the image still does not threshold as clear (meaning an all black image).  Am I missing something or is there something else that I can try?

Thanks in advance!

Jen


Grayscale image that contains no particles.  It actually contains some particles but these particles are too small for my measurements.

Threshold of the grayscale image above.

Count and Measure of the image showing the program finding particles that are not there due to the illumination.

Background Image

Background Corrected

Best Answer

  • Answer ✓
    2017-08-22-095209

    Jen --

    If this was my project, I would:

    ** Take a small sample of images from the overall sample set (maybe 10) and make sure that they represent the variety that you see in the overall sample set
    ** Perform the CONVERT and FLATTEN on each image
    ** Get the HISTOGRAM STATISTICS for each image
    ** Set the THRESHOLD manually for each image

    After doing this it should be possible to see if there is a mathematical method that can use the HISTOGRAM STATISTICS to set a good THRESHOLD.

    The HISTOGRAM STATISTICS can be accessed and used to control the THRESHOLD as follows:

        'Declare the variable that will hold the histogram stats
        ReDim MyHstStats (10) As Single
        'MyHstStats (0) - Mean value
        'MyHstStats (1) - Standard Deviation
        'MyHstStats (2) - Sum
        'MyHstStats (3) - Minimum gray level (X-MIN)
        'MyHstStats (4) - Maximum gray level (X-MAX)
        'MyHstStats (5) - Not Currently Used
        'MyHstStats (6) - Not Currently Used
        'MyHstStats (7) - Not Currently Used
        'MyHstStats (8) - Not Currently Used
        'MyHstStats (9) - Not Currently Used

        'Acquire and remember the histogram stats for enhanced image
        ret = IpHstGet(HSTGET_GETSTATS,0,MyHstStats(0))
        Dim MyStatsMEAN As Single
        MyStatsMEAN = MyHstStats(0)
        Dim MyStatsSTDV As Single
        MyStatsSTDV = MyHstStats(1)

        'Set the threshold based on the stats for the current image
        ret = IpSegSetRange(0, Round (MyStatsMEAN + (3 * MyStatsSTDV) ), 255)
        ret = IpSegPreview(CURRENT_C_T)

    In the case shown above, I believe that the objects that were being THRESHOLDED and COUNTED were bright (??? to 255).

    I hope this information is helpful.

    -- Matt

Answers

  • 2017-08-21-102945

    Jen --

    Based on my interpretation of your question, I took your image and did a process which may help you.

    Please see the SCREEN CAPTURES and the DESCRIPTIONS below.

    I hope this information is helpful.

    -- Matt

    *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-


    ORIGINAL IMAGE = RGB 24
    MONO 8 is GRAY CONVERSION of ORIGINAL
    FLATTENED = PROCESS + FILTERS + ENHANCEMENT + FLATTEN + BRIGHT + 50 (As shown)
    Tiled = MONO 8 on LEFT + FLATTEN on RIGHT + AUTO DARK THRESHOLD



    FLATTENED IMAGE from above
    HISTOGRAM showing MEAN of 150, STD DEV 2
    THRESHOLD of 0 to MEAN (MEAN - ( 5 * STD DEV ) ) and COUNT with MIN SIZE FILTER 20 SQ PIX
  • Matt,
    Thanks for your response!  I followed you until the threshold part.  When I threshold with a min Area filter of 30 I still get tons of particles from the flattened image. 
    -Jen
  • 2017-08-21-110232

    Jen --

    I was working with an UNCALIBRATED IMAGE so my MIN AREA SETTING of 20 is in SQ PIX.

    If your image is CALIBRATED, you need to adjust your MIN AREA accordingly.

    Oops . . . .

    According to the SCREEN CAPTURE, my MIN AREA was set to 30.  Sorry about that typo.

    I hope this information helps.

    -- Matt
  • Hey Matt,
    Unfortunately I'm still not getting the image you're getting. Maybe I'm missing a step where you auto dark threshold. Because when I threshold I get those "waves" from the flattening filter that you show in the tiled image. How did you get from that to the background of just the particles? Sorry if this is easy and I'm just not getting it. 
    -Jen
  • 2017-08-21-135857

    Jen --

    It sounds like your THRESHOLD is not set right.

    I believe that mine was set from 0 (BLACK) to 140 to capture the PARTICLES but to ignore the (brighter) BACKGROUND.

    Try that and let me (us) know how it goes.

    -- Matt
  • Ok I get it now and that is what I'm having the issue with. I can manually set the threshold to the correct value but I am trying to have it automatically set to the correct threshold value. Is there a way to have it set automatically or will I have to manually set a threshold for each. I have about 4,200 images for each sample and a good number of samples so I'd like it to be automated if it's possible. 

    -Jen
  • edited August 2017
    Jen,

    "Auto-dark" uses automatic histogram-based thresholding according to Otsu algorithm. On images with no or few small dark spots (like yours) it may segment the backround itself, so you should not use "Auto-dark" with your images, but rather use fixed level thresholding on background corrected images.
    Extract background using the Background filter

    and then Subtract it from the original image adding some shift, e.g. 100:

    then do Count using a fixed threshold below the shift, e.g. 70.

    Record all these steps to a macro and use this macro for all your 4200 images.

    Yuri

  • 2017-08-21-173628

    Jen --

    See if YURI's suggestion works for you.

    Another way is to extract the HISTOGRAM for the ENTIRE IMAGE and then use the STATISTICS to set the THRESHOLD.

    This may not work well if the character of your images changes dramatically and YURI's suggestion may work better.

    Good luck.

    -- Matt
  • Thank you Yuri and Matt for your suggestions.

    Yuri-I was hoping I wouldn't have to do a fixed threshold because some images have lots of particles and some none (like shown above) so I was worried about measuring bias. But I'm starting to see that I may have to anyway. 

    Matt-I'm interested in trying to see if setting the threshold by the histogram statistics would work. All the images are taken at the same ExpPwr and same voltage setting on the microscope to keep a similar background intensity. The intensity stays around 120-140. The only thing that seems to change is the mean of the histogram based on how many particles are in the field of view. How do I threshold based on the statistics? And would I be able to write a macro for it?

    Thank you so much for all your help with this! I've learned so much already!
  • 2017-09-11-085005

    Jen --

    In an earlier message and below there is a bit of IMAGE-PRO PLUS CODE that illustrates how to READ the HISTOGRAM STATISTICS and SET the THRESHOLD based on the those STATS.

    I hope this information is helpful.

    -- Matt

    *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-

    The HISTOGRAM STATISTICS can be accessed and used to control the THRESHOLD as follows:

        'Declare the variable that will hold the histogram stats
        ReDim MyHstStats (10) As Single
        'MyHstStats (0) - Mean value
        'MyHstStats (1) - Standard Deviation
        'MyHstStats (2) - Sum
        'MyHstStats (3) - Minimum gray level (X-MIN)
        'MyHstStats (4) - Maximum gray level (X-MAX)
        'MyHstStats (5) - Not Currently Used
        'MyHstStats (6) - Not Currently Used
        'MyHstStats (7) - Not Currently Used
        'MyHstStats (8) - Not Currently Used
        'MyHstStats (9) - Not Currently Used

        'Acquire and remember the histogram stats for enhanced image
        ret = IpHstGet(HSTGET_GETSTATS,0,MyHstStats(0))
        Dim MyStatsMEAN As Single
        MyStatsMEAN = MyHstStats(0)
        Dim MyStatsSTDV As Single
        MyStatsSTDV = MyHstStats(1)

        'Set the threshold based on the stats for the current image
        ret = IpSegSetRange(0, Round (MyStatsMEAN + (3 * MyStatsSTDV) ), 255)
        ret = IpSegPreview(CURRENT_C_T)

  • Thank you Matt.  It was very helpful!

    -Jen
Sign In or Register to comment.