Home Image-Pro General Discussions

D10, D50, D90 Partical Size Distribution calculation in Image-Pro

D10, D50 and D90 is a common Particle Size Distribution (PSD) standard used among pharma customers.

For instance, D50 gives the diameter median value of the size distribution, which means diameter at 50% in the cumulative distribution.

As we cannot do the complete calculation in Image-Pro, is there any way we can perform the complete calculation and the graph generation in Image-Pro for D10, D50 and D90 particle size distribution.

Thank you!

Answers

  • edited August 2021
    Hi Brijeshwar,

    Statistical values of Median (D50), D90 and D10 will be available in the next version of Image/Pro. 

    In the current version you can use the following macro to get percentile stats of the measurements on the active image (e.g. Diameter):

    
    
    <pre>    
       Public Sub PrintPercentileStats
            Dim im As McImage=ThisApplication.ActiveImage
            If im Is Nothing Then Exit Sub
            Dim md As MediaCy.Addins.Measurements.McMMData=im.MeasurementsData
            If md.SubFeatures.Count=0 Then Exit Sub' no measurements
            Dim vals As New System.Collections.ArrayList
            'get diameter measurements (change for other measure if necessary)
            Dim measure As eMeasures=eMeasures.RgnMeanDiameter
            For Each sf As McMMSubFeature In md.SubFeatures
                vals.Add(sf.Value(measure))
            Next
            'measure 3 percentiles
            Dim percentiles As Double()={10,50,90}
            For Each p As Double In percentiles
                Debug.Print (String.Format("D{0} of {1} = {2}",p,measure.ToString,GetPercentileValue(vals.ToArray(),p)))
            Next
        End Sub
    
        Public Function GetPercentileValue(vals As Object, Percentile As Double) As Object
            If vals Is Nothing Then Return 0
            If Not IsArray(vals) Then
                Return vals
            End If
            Dim inLength As Integer = vals.GetUpperBound(0) + 1
            System.Array.Sort(vals) 'sort
            Dim ind As Integer = System.Math.Round(Percentile * inLength / 100, 0, System.MidpointRounding.AwayFromZero) - 1
            ind = System.Math.Max(0, ind)
            ind = System.Math.Min(inLength - 1, ind)
            Return vals(ind)
        End Function
    </pre>
    
    
    

    the result will look like this:
    D10 of RgnMeanDiameter = 14,6595344023042
    D50 of RgnMeanDiameter = 17,6075513462399
    D90 of RgnMeanDiameter = 21,3247373718319

    Yuri
  • Hello Yuri,

    I have tested the macro shared by you and I am facing the below attached error in the code, kindly guide me to resolve this issue.


    Thank you!
  • Hi Brijeshwar,

    You have to remove <pre> tags, before and after.

    Yuri
  • Hello Yuri,

    I have tested the macro after removing <pre> tags, before and after from the code still I am facing the same error.

    Please find attached screenshot for your ready reference.

    Thank you!
  • Hi Brijeshwar,

    It looks like you pasted the code into a wrong place, outside the Module block. Try to paste these 2 functions in the Module block. If you don't see that, create a new project.

    Yuri
  • Hi Yuri,

    I have created a new project and I have pasted the code in the new project, and now I am facing a new error.

    Please find below screenshot for your ready reference.


    Thank you!
  • Hi Brijeshvar,

    It looks like you pasted the macro to a wrong file, you should paste it to Module.vb, not Macro.ipp.

    You may load one of the existing projects, as example and see where all macros are located. 

    Yuri

  • Hi Yuri,

    I have pasted the macro to Module.vb, and still I am facing the error.


    Thank you!
  • Hi Brijeshwar,

    Sorry for making it difficult,  I will come back from vacation on Thursday and post the complete project with these 2 macros. 

    Regards,

    Yuri

  • Hi Brijeshwar,

    I've created a project that includes these macros. You can just unzip the attached file and load  PercentileStats.ipx project to Image-Pro. Then you can run the PrintPercentileStats macro and the values (D10,D50,D90) will be printed to the Output window:



    Let me know if you have questions,

    Regards,

    Yuri
  • Hi Yuri,

    Thank you for sharing the macro project, now its working.

    Thank you!

    Regards,
    Brijeshwar
Sign In or Register to comment.