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

pixel level manipulation too slow and needs to work on larger image

''Can this code be made to work faster, it is very slow. Also, crashing a lot on images of larger size. It seems to work ok on some very small demo images, otherwise not good. What are the options? Extract each channel and read\write and then merge back together?  I see a function\option of CopyInEntireArea ? , but no example code? Also what is FastAccess property? 

Public Sub PixelOperationsTestColor()
        Dim im As McImage=ThisApplication.ActiveImage
        If im Is Nothing Then Exit Sub
        If im.NumberOfChannels=1 OrElse im.BitsPerChannel>8 Then Exit Sub'support only 8-bit color image
        'create region access for whole image of color 8-bit image
        Dim ra As McRegionAccess=im.CreateRegionAccess()
        ra.RegionMask=im.Aoi'process only active ROI
        Dim data(,,) As Byte
        'get 3D array of pixel data
        For c As Integer=0 To data.GetUpperBound(0)
            For i As Integer=0 To data.GetUpperBound(1)
                For j As Integer=0 To data.GetUpperBound(2)
        'put data back
    End Sub

Best Answer

  • Accepted Answer
    In code view, on the project page, you add a reference to the compiled project then you can call macros and functions using the syntax <Compiled Project Name>.[Module Name].<Sub Name>.
    Project Project1
        Optimizer Off
        'Add references to other projects using ReferenceProject.
        'ReferenceProject "filename"
        ReferenceProject "..\Project3\Project3.ipp"
        LoadModule "Macros.vb"
     End Project
        Public Sub CallProject3
        End Sub


  • Hello,

    You can make this code run much faster by running it in a compiled project. You can either change the entire project to "compiled" on the project Properties page, or isolate this type of function in its own compiled project that can then be called from other interpreted projects. Compiled projects end up running native binary code so they could be hundreds times faster than interpreted ones.

    FastAccesss would attempt to return the actual image memory if possible which would save 2 copies (no need for PutArea) but is not guaranteed to always succeed, depending on the image size the number of frames etc...

  • You can also use built in operations on images, check IMcOperations interface. Your sub can be replaced with this line: 
    You can use sequence of the operation on images to do the processing you need (Add, Sub, Mult,...).


  • got it working as compiled project. How do I call a compiled project from another project?

Sign In or Register to comment.