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

Colour Composites

Hello

I'm writing an automation which requires a 3 colour composite image. I tried 4 lines of code below which I assumed would either create a blank composite image or add the McImage to make a new composite window.

	Dim doc1
        doc1 = MediaCy.Automation.Adjust.ColorCompositeCommands.New

        croppedred = ThisApplication.ActiveImage
        croppedred = MediaCy.Automation.Adjust.ColorCompositeCommands.Add

 I used the ColorCompositeCommands Class help section which suggests that Add or New are methods. When I debug I get a Method Not Found error. I've imported the following

Imports MediaCy.Automation.Adjust.ColorCompositeCommands

Does Add or New have some other input. I know I could record this but the code for the full automation is now absolutely massive and hard to read so I'm trying to slim it down and figure out some more of the programming structure. All help much appreciated.

Regards

David

Best Answer

  • Options
    edited September 2014 Answer ✓
    Sorry, I was testing the macro in a newer version, 9.1.2 indeed produces an error (couldn't handle missing parameter).
    The version below will work in 9.1.2:

        Public Sub MergeChannelsToColorImage
            'Create a global McColorModel operator (one with no parent)
            Dim mccolormodel As MediaCy.IQL.Operations.McColorModel=ThisApplication.CreateOperator( "McColorModel")
            'Use it to create a new, merged image
            Dim channelImages(2) As Object
            channelImages(0)=ThisApplication.ActiveImage
            channelImages(1)=ThisApplication.ActiveImage'use different image
            channelImages(2)=ThisApplication.ActiveImage
            Dim outIm As McImage= mccolormodel.MergeMultipleChannels(channelImages,New Integer(){0,1,2},mcInterpretation.mciRGB)
        End Sub
    
    

    Yuri

Answers

  • Options
    David,

    Commands cannot be used that way. Every command has Input and Output, specific properties and executed using Run method. 

    If you want to use commands, the best way is to record a macro doing these steps.

    Below is the macro that creates color composite from 3 last active images:

        Public Function CreateColorComposite() As SimpleScript
            CreateColorComposite = New SimpleScript
            Dim doc1, image1
            Dim var1 = 1, image2, win2
            Dim var2 = 2, image3, win3
    
            With Application.DocumentCommands.ActiveImage(CreateColorComposite)
                .Run(image1)
            End With
    
            With Adjust.ColorCompositeCommands.New(CreateColorComposite)
                .Run(doc1)
            End With
    
            With Application.DocumentCommands.Activate(CreateColorComposite)
                .Run(doc1, doc1)
            End With
    
            With Adjust.ColorCompositeCommands.Add(CreateColorComposite)
                .Run(doc1, image1)
            End With
    
            With Application.WindowCommands.Define(CreateColorComposite)
                .Run(var1, win2)
            End With
    
            With Adjust.ImageCommands.Define(CreateColorComposite)
                .Run(win2, image2)
            End With
    
            With Adjust.ColorCompositeCommands.Add(CreateColorComposite)
                .Run(doc1, image2)
            End With
    
            With Application.WindowCommands.Define(CreateColorComposite)
                .Run(var2, win3)
            End With
    
            With Adjust.ImageCommands.Define(CreateColorComposite)
                .Run(win3, image3)
            End With
    
            With Adjust.ColorCompositeCommands.Add(CreateColorComposite)
                .Run(doc1, image3)
            End With
    
        End Function
    

    Regards,

    Yuri
  • Options
    edited September 2014
    David,

    If your goal is to slim down the code, you can use McColorModel for that and merge channels to a color image.

        Public Sub MergeChannelsToColorImage
            'Create a global McColorModel operator (one with no parent)
            Dim mccolormodel As MediaCy.IQL.Operations.McColorModel=ThisApplication.CreateOperator( "McColorModel")
            'Use it to create a new, merged image 
            Dim channelImages(2) As Object
            channelImages(0)=ThisApplication.ActiveImage
            channelImages(1)=ThisApplication.ActiveImage'use different image
            channelImages(2)=ThisApplication.ActiveImage
            Dim outIm As McImage= mccolormodel.MergeMultipleChannels(channelImages,,mcInterpretation.mciRGB)
        End Sub
    
    

    Yuri
  • Options

    Hello Yuri

    Its the code slimming option I'm after. Just tried it and I get a type mismatch error and it creates a blank image. Looking at the code this is for single planes, I forgot to mention that my 3 images are Z stacks and I'll be using the colour image to create a 3D image for measurement. Will doing it this way work z stacks and 3D measurements.

    Regards

    David

  • Options
    This code should work for stacks as well, I just tested.
    Just try it with some demo images, for example load Heart.seq and run this macro.

    Yuri
  • Options

    Hello Yuri

    Thanks, that worked. The IQL commands appear to be the way to go to keep code short and more readable.

    Regards

    David

  • Options
    Hello, 
    Attempted to use this code as written. Receive the error; "Object does not expose the required interface" What am I doing wrong?
Sign In or Register to comment.