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

Extractin Channels from czi image sets

Hi,

I have the problem that I want to extract a channel from CZI images to run automated analyses.

First steps are simple and should include:

Extraction of one channel, making an 8bit grey scale of if and work on it.

It opens in color composite view. If I subsample it is dependent on the view. When I record macro, I always get the error that methods are not found, thus I can't automate:

In this case: Active RegionInUse not found:

With New MediaCy.Viewers.Set.ImageSetViewOptionsCommand(grrrr)
            .ActiveRegionInUse = MediaCy.IQL.Sets.mcImageSetActivePortionTypes.mcisaptActiveDisplayRegion
            .Run(window1)
        End With
or other method (changing view, directly switch channel and extract grey scale)
Public Function Grr2() As SimpleScript
        Grr2 = New SimpleScript
        Dim var1 = "6_15_L17_2", doc1, window1, image1, doc2

        With Application.DocumentCommands.Activate(Grr2)
            .Run(var1, doc1)
        End With

        With Application.WindowCommands.Define(Grr2)
            .Run(doc1, window1)
        End With

        With New MediaCy.Viewers.Set.ImageSetViewOptionsCommand(Grr2)
            .ColorCompositeView = False
            .Run(window1)
        End With

        With Application.DocumentCommands.Activate(Grr2)
            .Run(doc1, doc1)
        End With

        With New MediaCy.Viewers.Set.ImageSetViewOptionsCommand(Grr2)
            .ViewLocation = New McImageSetLocations
            .ViewLocation.Add(mcImageSetDimensions.mcisdChannel, 1)
            .Run(window1)
        End With

        With Application.RibbonCommands.SelectRibbonTab(Grr2)
            .TabName = "Adjust"
            .Run()
        End With

        With Adjust.ImageCommands.Convert(Grr2)
            .Destination = Image.ConvertTypes.Mono8
            .ConvertOption = Image.ConvertOptions.Custom
            .SourceRange = New RangeD(0R, 4096R)
            .DestinationRange = New RangeD(0R, 255R)
            .Visible = True
            .Run(doc1, image1)
        End With

        With Application.DocumentCommands.Activate(Grr2)
            .Run(image1, doc2)
        End With

    End Function

In this case the method .colorCompositeView is not found if repeating the script. 
In detail: MediaCy.IQL.Application.McCommandExtended.ColorCompositeView not found...

Is there some lib to integrate that those commands work?

Many thx

Daniel

Best Answer

  • Options
    Answer ✓
    Hi Dan,

    It looks like there is a problem with that command in 9.1.4. We are going to release a new Premier version pretty soon, but right now you can use the attached project, which shows how to extract all Z-stacks from image set without using that command:

        Public Sub ExtractZStacksFromActiveImage
            Dim imset As MediaCy.IQL.Sets.McImageSet=ThisApplication.ActiveDocument.Data
            If imset Is Nothing Then Exit Sub'this is not image set
            'get number of channels in stack
            Dim nChannels As Long=imset.GetDimensionLength(mcImageSetDimensions.mcisdChannel,imset.GetCurrentLocation)
            For chInd As Integer=0 To nChannels-1
                ExtractZStackFromChannel(imset,chInd)
            Next
        End Sub
    
    
        Public Sub ExtractZStackFromChannel(imset As MediaCy.IQL.Sets.McImageSet,chInd As Long)
            Dim setLoc As New MediaCy.IQL.Sets.McImageSetLocations
            'select channel to location
            setLoc.Add(mcImageSetDimensions.mcisdChannel, chInd)
            'get number of frames in Z dimension
            Dim nZframes As Long=imset.GetDimensionLength(mcImageSetDimensions.mcisdZ,setLoc)
    
            'create region to extract
            Dim theRegion As MediaCy.IQL.Sets.McImageSetRegion=ThisApplication.CreateOperator("McImageSetLib.McImageSetRegion")
            Dim theSections As MediaCy.IQL.Sets.McImageSetSections = theRegion.Sections
            theSections.Add(mcImageSetDimensions.mcisdChannel,chInd,1)
            theSections.Add(mcImageSetDimensions.mcisdZ,0,nZframes)
            'create image of Z frames (invisible)
            Dim outIm As McImage=imset.ExtractImage(theRegion, mcImageCreateFlags.mcicfNotVisible Or mcImageCreateFlags.mcicfNoAddToCollection)
            'show image
            outIm.Visible=True
        End Sub
    
    Let me know if it will work for you,

    Regards,

    Yuri

Answers

  • Options
    Hi Daniel,

    What version of Premier do you have? The current version is 9.1.4, it can be updated automatically at startup.

    Please try the macro below, that works in 9.1.4:

        Public Function ExtractActiveChannel() As SimpleScript
            ExtractActiveChannel = New SimpleScript
            Dim doc1, spcal1, window1, image1, doc2, image2, doc3
    
            With Application.DocumentCommands.Active(AutoThreshold)
                .Run(doc1)
            End With
    
    
            With Application.WindowCommands.Define(ExtractActiveChannel)
                .Run(doc1, window1)
            End With
    
            With New MediaCy.Viewers.Set.ImageSetViewOptionsCommand(ExtractActiveChannel)
                .ColorCompositeView = False
                .Run(window1)
            End With
    
            With Adjust.ImageSetCommands.ExtractDimension(ExtractActiveChannel)
                .Dimension = MediaCy.IQL.Sets.mcImageSetDimensions.mcisdDefault
                .Run(doc1, image1)
            End With
    
            With Application.DocumentCommands.Activate(ExtractActiveChannel)
                .Run(image1, doc2)
            End With
    
            With Adjust.ImageCommands.Convert(ExtractActiveChannel)
                .Destination = Image.ConvertTypes.Mono8
                .ConvertOption = Image.ConvertOptions.Scale
                .Visible = True
                .Run(doc2, image2)
            End With
    
            With Application.DocumentCommands.Activate(ExtractActiveChannel)
                .Run(image2, doc3)
            End With
    
        End Function
    
    

    Regards,

    Yuri
  • Options

    Thanks Yuri,

    According to SW it's version 9.1.5638.4....Premier 3D version.

    Now type identifier invalid in line

    With New MediaCy.Viewers.Set.ImageSetViewOptionsCommand(ExtractActiveChannel)


    Those are imported - something missing?

    Imports MediaCy.Addins.SCalibration.Commands
    Imports MediaCy.Addins.Scripting
    Imports MediaCy.Addins.SCalibration
    Imports MediaCy.Addins.Scripting.Workflow
    Imports MediaCy.Viewers.Image
    Imports MediaCy.Viewers.Set
    Imports MediaCy.IQL.Sets

  • Options
    Hi Daniel,

    It could be that the version you have doesn't have definition for ImageSetViewOptionsCommand (there was a bug about it).
    To verify that please try to disable this command (comment it out):

           With New MediaCy.Viewers.Set.ImageSetViewOptionsCommand(ExtractActiveChannel)
                .ColorCompositeView = False
                .Run(window1)
            End With

    Let me know if that's fixed the error.

    Regards,

    Yuri 
  • Options

    Hi Yuri,

    did not fix it. now

    .Dimension = MediaCy.IQL.Sets.mcImageSetDimensions.mcisdDefault

    in the next with block returns that a valid data type is expected.

    Thus the MediaCy.IQL.Sets.mcImageSetDimensions.mcisdDefault object is not found.

    If I replace with integer 0 then it extracts a set with both channels, 1 to 4 different dimensions of channel 1. 5 upwards always channel 1 (gave up at six)

    However, at least with 0 I can work if I can switch in the set.


    Best

    Dan

Sign In or Register to comment.