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

CODE to force an update of the IMAGE HISTOGRAM . . .

2021-03-25-183933

All --

I am using the CODE below to display the IMAGE HISTOGRAM for an IMAGE / ROI.

                With Application.Gadgets.ImageHistogram(Nothing)
                    .CheckState = MediaCy.IQL.Application.McCommand.mcCheckState.Checked
                    .Run()
                End With

The CODE for the APP changes the ROI but the IMAGE HISTOGRAM does not update after the ROI is created by the CODE.

I have used CODE shown below after the ROI is created by the APP to update the IMAGE HISTOGRAM but it does not seem to work while the APP is actively doing something.

        'REFRESH THE UI
        MyControl.Refresh

        DoEvents

        'REFRESH THE IMAGE WINDOW
        ThisApplication.ActiveWindowEx.Refresh

        'REFRESH THE MEASUREMENT DATA
        ThisApplication.ActiveImage.MeasurementsData.Refresh

Is there CODE that will force the IMAGE HISTOGRAM to update while the APP is executing routines?

Thanks.

-- Matt

Answers

  • Options
    Matt,

    In my tests with the macro below, the histogram is updated automatically when ROI is added (histogram window is already opened):

        Public Function AddROI() As SimpleScript
            AddROI = New SimpleScript
            Dim image1
    
            With Application.RibbonCommands.SelectRibbonTab(AddROI)
                .TabName = "Select"
                .Run()
            End With
    
            With Application.DocumentCommands.ActiveImage(AddROI)
                .Run(image1)
            End With
    
            With [Select].RoiCommands.Add(AddROI)
                .ROIType = Features.ROI.ROITypes.Rectangle
                .Points = New System.Collections.Generic.List(Of System.Drawing.PointF)
                .Points.Add(New System.Drawing.PointF(428F,575F))
                .Points.Add(New System.Drawing.PointF(592F,658F))
                .Angle = 0R
                .Run(image1)
            End With
    
        End Function
    
    Please check if that macro will work for you.

    Regards,

    Yuri
  • Options
    2021-03-26-142144

    Yuri --

    Thank you for looking into this.

    I don't think your macro is testing the issue that I am seeing.

    If you make your macro create the ROI on the left side of an image with a GRAY WEDGE from LEFT to RIGHT and then you have your macro slide the ROI across the image, I think you will find that the HISTOGRAM does not update until the macro completes and focus within IMAGE-PRO is returned to the PRIMARY IMAGE-PRO INTERFACE.

    Thanks

    -- Matt


  • Options
    edited March 2021
    Hi Matt,

    Maybe you macro is running fast and the system is too busy for the UI updates. 
    You can add Wait function to the loop. The following example updates the histogram after every ROI move:

        Public Sub RollingROI
            Dim sz As Integer=100
            Dim im As McImage=ThisApplication.ActiveImage
            If im Is Nothing Then Exit Sub
            im.Aoi.Reset
            For y As Single=0 To im.Height Step sz
                For x As Single=0 To im.Width Step sz
                    im.Aoi.SetBox(0,x,y,x+sz,y+sz)
                    Wait(0.5)
                Next
            Next
        End Sub
    

    Yuri
  • Options
    2021-03-29-111725

    Yuri --

    Thank you for your CODE and your suggestion.

    There are WAIT commands within the ROUTINE A CODE (that moves the ROI) which is called by ROUTINE B (that does A and other things).  If the WAIT is within ROUTINE A but ROUTINE B is still active perhaps IP10 is not updating the HISTOGRAM with the new ROI.  I will try to put a short WAIT into ROUTINE B after the call to ROUTINE A to try to give IP10 the chance to catch up.

    This is an appearance issue only and is not generating a functionality problem so resolving it is polish oriented not performance oriented.

    Thanks again.

    -- Matt

Sign In or Register to comment.