Home Image-Pro Automation (Macros, Apps, Reports)

Measurements to ROI

Hello 
I have a ring measurement which I apply to other images however I also want to be able to threshold within this ring measurement when I apply it to other images. To do this I need to be able to convert it to an ROI, this is easy for a standard measurement and can be done in the features manager but it doesn't work for my ring measurement as it has an inner line and an outer line (doughnut). Is there any way to convert this type of non standard measurement to an ROI either manually so that the code can be recorded or any existing code.

Regards

David

Best Answer

  • Answer ✓

    Hi David,

    Features Manager doesn’t support all measurement variations. In order to convert "Donut" measurement into ROIs you need to call Convert Holes macro and then use Features Manager.

    Convert Holes macro converts “holes” into regular measurement.

        Public Function Convert_Holes() As SimpleScript
            Convert_Holes = New SimpleScript
            Dim doc1, meas
    
            With Application.DocumentCommands.Active(Convert_Holes)
                .Run(doc1)
            End With
    
            With Measure.MeasurementsCommands.GetData(Convert_Holes)
                .Run(doc1, meas)
            End With
    
            With Automate.ScriptingCommands.CodeCommand(Convert_Holes)
                If .Run() Then
                    ' User Code Here
                    Dim m As MediaCy.Addins.Measurements.McMMData
                    Dim f As MediaCy.IQL.Features.McRegions
    
                    m = TryCast(meas, MediaCy.Addins.Measurements.McMMData)
                    If m IsNot Nothing Then
                        For Each f In m.GetMcFeatures( McMeasurements.enumMMFeatures.mmfRegions)
                            If f.Holes.Count > 0 Then
                                f.Merge(f.Holes)
                            End If
                        Next
                    End If
                End If
            End With
    
        End Function
    

     

Answers

  • Hello Yuri

    I've had a look at the code and I see that f.Merge(f.Holes) is where the donut is created but I cannot use it. The count still remains for the whole donut and if I try to threshold and then count it does it on the whole image rather than the bit inside the donut. Where does the shape made by f.Merge appear as its not in the feature manager so I can't apply it.

    Regards

    David

  • Hello David,

    The Nikita's macro doesn't affect Count/Size and designed only as a preliminary step exporting outlines to Features Manager. 

    What you should do is:

    1. Create doughnut shape object using Count.
    2. Run the Convert_Holes macro.
    3. Add measurement features to the Features Manager - you should have there 2 polygons (inner and outer outline).
    4. Activate another image.
    5. In Featured Manager change features type from Measurements to ROIs.
    6. Copy features as ROIs to another image.
    7. Be sure that you have XOR ROIs option active
    8. Measure or count objects within the ring of doughnut shape ROI.

    Yuri
  • Sorry Nikita, should have spotted that it was you and not Yuri.
  • Hello David,

    Actually, I just tested the steps and found that you can copy doughnut ROI to another image even without the macro:

    1. Create doughnut shape object using Count.
    2. Add measurement features to the Features Manager - you should have there 1 polygon (outer outline), but it will contain an invisible hole.
    3. Activate another image.
    4. In Featured Manager change features type from Measurements to ROIs.
    5. Copy features as ROIs to another image.
    6. Measure or count objects within the ring of doughnut shape ROI. Note that ring will be active unless you move or modify ROi, in that case the hole will be lost, but if you are not going to modify ROI it will work fine.

    Yuri

  • For anyone reading this thread both solutions work. Thanks Nikita and Yuri

    David
Sign In or Register to comment.