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

Background Correction

I'm having problems with this. Trying to do background correction with dark objects.. This is the recorded script, but I just get a white image.


    Public Sub button1_Click_1(sender As Object, e As System.EventArgs) 
        With Process.BackgroundCommands.Correct(Nothing)
            .BlackLevel = 0R
            .Run(ThisApplication.ActiveDocument, ThisApplication.ActiveDocument, Nothing)
        End With

    End Sub

Answers

  • Hi Paul,

    The background correction includes 2 commands (Extract Background and Correct). You macro shows just one command. Please, try to record the macro and post it here.

    What is your Premier's version?

    Thanks,
    Nikita.

  • Paul,

    Your command looks edited manually the arguments in the Run function is not native. Does it work in the recorded version of the macro?
    Also, there was a fix in 9.3.1 related to this command. Please try 9.3.1 (if you don't use it already).

    Yuri

  • thanks for your comments - my recorded code is as below. When I run it I get a blank white image. 

    I'm still running 9.2 on this computer - perhaps I need to got to 9.3 as you suggest.

        Public Sub button3_Click(sender As Object, e As System.EventArgs) Handles button3.Click
            With Process.BackgroundCommands.Correct(Nothing)
                .BlackLevel = 0R
                .Run(ThisApplication.ActiveDocument, ThisApplication.ActiveDocument, Nothing)
            End With
    
        End Sub
  • Paul,

    I recorded and tested the background correction macro in Premier. The macro looks like this (it works properly in 9.3.1):
        Public Function CorrectBrightBackground() As SimpleScript
            CorrectBrightBackground = New SimpleScript
            Dim doc1, image1
    
            With Application.DocumentCommands.Active(CorrectBrightBackground)
                .Run(doc1)
            End With
    
            With Process.BackgroundCommands.Extract(CorrectBrightBackground)
                .BackgroundType = Background.ExtractTypes.Bright
                .FeatureSize = 50
                .Visible = False
                .Run(doc1, image1)
            End With
    
            With Process.BackgroundCommands.Correct(CorrectBrightBackground)
                .BlackLevel = 0R
                .Run(doc1, image1, doc1)
            End With
    
        End Function
    
    

    The easiest way to do what you need is just to call the recorded macro from your event handler (instead of copy/pasting the code), even if the recorded macro is in different VB module of your project:

        Public Sub button3_Click(sender As Object, e As System.EventArgs) Handles button3.Click
            CorrectBrightBackground
        End Sub

    Yuri
      
  • still getting an error from .Run(doc1, image1, doc1) - specified caste is not valid

    have to upgrade to 9.3 - thanks for your help anyway. 


  • Hi Paul,

    There is an issue in the background commands recording/playback and we are looking on it.

    The current solution is simplified macro then background image generated internally:

        Public Function CorrectBrightBG() As SimpleScript
            CorrectBrightBG = New SimpleScript
            Dim doc1
    
            With Application.DocumentCommands.Active(CorrectBrightBG)
                .Run(doc1)
            End With
    
            With Process.BackgroundCommands.Correct(CorrectBrightBG)
                .BackgroundType = Background.BackgroundTypes.Bright
                .FeatureSize = 50
                .BlackLevel = 0R
                .Run(doc1, Nothing, doc1)
            End With
        End Function
    

    Thanks,
    Nikita.
  • Paul, if you upgrade to 9.3, please make sure to install 9.3.1 patch as well.

    Thanks,
    Nikita.
Sign In or Register to comment.