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

CODE to perform a SNAPSHOT within an ROI . . .

2021-10-13-172317

All --

I am looking for the equivalent of the SNAPSHOT COMMAND but I would like the image that is the result to be just the ROI.

So as an example . . .

I have an image that is 3000 x 3000 pixels.  I would like to work with an ROI that is 1000 x 1000.  I have done a COUNT in the ROI. Now I would like a SNAPSHOT of just the ROI.

Here is an illustration with:

-- AA on the left being the 3000 x 3000 image with the 1000 x 1000 ROI with the COUNT within it
-- BB on the right being the SNAPSHOT of the 1000 x 1000 ROI with the COUNT burned into it.



I did this manually by:

-- Saving the ROI from AA in the FEATURES MANAGER
-- Doing a SNAPSHOT on AA
-- Recalling the ROI from AA into the SNAPSHOT
-- Cropping the 3000 x 3000 pixel SNAPSHOT to the appropriate 1000 x 1000 SNAPSHOT
-- Deleting the 3000 x 3000 pixel SNAPSHOT

The result of these steps is BB.

Is there an efficient way to do this with CODE or should I write CODE to perform the steps that I did manually to get from AA to BB?

I know that I could CROP AA to the ROI before doing the COUNT, do a COUNT on the CROPPED IMAGE, and then do a SNAPSHOT of the CROPPED + COUNTED IMAGE but I would like to avoid working with an INTERMEDIATE IMAGE if possible.

Thanks.

-- Matt

Best Answer

  • Options
    edited October 2021 Answer ✓
    Hi Matt,

    There is no direct option to do what you want, but here is a macro that does it executing your steps on invisible image:

        Public Sub SnapshotOfROI
            Dim im As McImage=ThisApplication.ActiveImage
            Dim image1 As McImage
            With Application.WindowCommands.Snap(Nothing)
                .Visible=False'create invisible snapshot
                .Run(ThisApplication.ActiveWindow, image1)
            End With
            'apply original image ROI
            image1.Aoi.CopyFrom (im.Aoi)
            'duplicate and make it visible
            image1.Duplicate(mcImageCreateFlags.mcicfDefault).Visible=True
            image1.Close
        End Sub
    
    This macro leaves ROI outline on snapshot.

    And here is the macro that does't have ROI outline
        Public Sub SnapshotOfROIWithoutGreenBorder
            Dim im As McImage=ThisApplication.ActiveImage
            Dim image1 As McImage
            Dim roi =im.Aoi.Duplicate'save the ROI
            'Clear ROI To avoid green line On screenshot
            im.Aoi.Reset
            With Application.WindowCommands.Snap(Nothing)
                .Visible=False'create invisible snapshot
                .Run(ThisApplication.ActiveWindow, image1)
            End With
            im.Aoi.CopyFrom (roi)'restore original ROI
            'apply original image ROI
            image1.Aoi.CopyFrom (im.Aoi)
            'duplicate and make it visible
            image1.Duplicate(mcImageCreateFlags.mcicfDefault).Visible=True
            image1.Close
        End Sub
    

    Yuri

Answers

  • Options
    2021-10-14-160338

    Yuri --

    Those routines are SUPER.

    I hotwired them into the APP and they both work great.

    I think that

        SnapshotOfROI

    will be the one that we use but it is nice to have the option.

    Thank you.

    -- Matt



Sign In or Register to comment.