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

Automation Issue with SPATIAL CALIBRATION on RESIZED IMAGE . . .

All --

In a recent DISCUSSION, a method was publicized for "transferring" a SPATIAL CALIBRATION from an IMAGE1 to an IMAGE2.

I wired the method into my software and all was well until I tried to use this method on an image that had been RESIZED by IPP904.

It seems that there is something that the

        image2.SpatialCalibration = image1.SpatialCalibration

method does not like about the SPATIAL CALIBRATION in RESIZED IMAGES.

I've created subroutines and a TIF file that demonstrate this issue on my computer.  There is something about the way I did the VB file that does not want to package into an IPX file so here are the routines and the TIF image is attached.

    Public Sub OpenDemoImage()
        Dim docList1 = New List(1), doc1

        With Application.DocumentCommands.Open(Nothing)
            .Filenames = New String() {MacroDir & "\300_1.tif"}
            .Run(docList1)
        End With

        With Application.DocumentCommands.Activate(Nothing)
            .Run(docList1(0), doc1)
        End With

    End Sub


    Public Sub Resize()
        Dim doc1, image1

        With Application.DocumentCommands.Active(Nothing)
            .Run(doc1)
        End With

        With Adjust.ImageCommands.Resize(Nothing)
            .Size = New System.Drawing.Size(600,600)
            .Smoothing = MediaCy.IQL.Operations.mcSmoothing.mcsmBilinear
            .Visible = True
            .Run(doc1, image1)
        End With

    End Sub


    Public Sub MaskAndCalibrate()
        Dim doc1, image1, image2

        'Learn the information about the current image
        image1 = ThisApplication.ActiveImage

        With Measure.MeasurementsCommands.Options(Nothing)
            .Segmentation.AutoFindPhase = MediaCy.IQL.Features.mcFindPhase.mcfpManual
            .Segmentation.SegmentationType = McMMOptions.mcmmSegmentationType.mcmmstThresholdSegmentation
            .Run(doc1)
        End With

        With Measure.ThresholdToolCommands.CreateMask(Nothing)
            .Run(doc1, image2)
        End With

        'Transfer the calibration information from the original image into the mask image
        image2.SpatialCalibration = image1.SpatialCalibration

    End Sub


    Public Sub CloseAllImages()

        With Application.WindowCommands.CloseAll(Nothing)
            .Run()
        End With

    End Sub
This code is also attached as

    2013-08-14-151003.txt

With the TIF file in the same folder as the VB file , when I

     -- Run OPENDEMOIMAGE
     -- Skip RESIZE
     -- Run MASKANDCALIBRATE

everything works fine.

You can then

     -- Run CLOSEALLIMAGES

to "reset" the system.

When I

     -- Run OPENDEMOIMAGE
     -- Run RESIZE
     -- Run MASKANDCALIBRATE

I get an error (attached in 2013-08-14-145203.jpg) that starts with "OBJECT IS NOT AN OPERATOR".

It seems that there is something within the mechanism behind

            image2.SpatialCalibration = image1.SpatialCalibration

that does not like the calibration that is created by the RESIZE operation.

This is probably not a "monster" issue because normally measurements would be made on a "native" image and not resized first but resizing did make sense for a trial I was doing and this issue showed up!

Is there a way to work around this?

Thanks.

-- Matt

Best Answer

  • Options
    Answer ✓
    Matt,

    There is apparently a problem with the way that a derived calibration is created after the image is resized, it's missing some internal information which would allow it to be assigned to another image. I added a call in the Resize macro to workaround this issue until it's fixed in Premier 9.1.

    Also note that in the MaskAndCalibrate macro, the variable doc1 was never assigned, so I replaced it with image1.

    Pierre
        Public Sub Resize()
            Dim doc1, image1
    
            With Application.DocumentCommands.Active(Nothing)
                .Run(doc1)
            End With
    
            With Adjust.ImageCommands.Resize(Nothing)
                .Size = New System.Drawing.Size(600,600)
                .Smoothing = MediaCy.IQL.Operations.mcSmoothing.mcsmBilinear
                .Visible = True
                .Run(doc1, image1)
            End With
    
            ThisApplication.McObjects.Add(mediacy.IQL.ObjectManager.mcobjTypeEnum.mcobjTypeXOBJECT,,,image1.SpatialCalibration)
    
        End Sub
    
    
        Public Sub MaskAndCalibrate()
            Dim image1, image2
    
            'Learn the information about the current image
            image1 = ThisApplication.ActiveImage
    
            With Measure.MeasurementsCommands.Options(Nothing)
                .Segmentation.AutoFindPhase = MediaCy.IQL.Features.mcFindPhase.mcfpManual
                .Segmentation.SegmentationType = McMMOptions.mcmmSegmentationType.mcmmstThresholdSegmentation
                .Run(image1)
            End With
    
            With Measure.ThresholdToolCommands.CreateMask(Nothing)
                .Run(image1, image2)
            End With
    
            'Transfer the calibration information from the original image into the mask image
            image2.SpatialCalibration = image1.SpatialCalibration
    
        End Sub
    

Answers

  • Options
    Pierre --

    Thank you for looking into this matter, discovering the underlying issue, providing a workaround, and starting the gears turning to eliminate this from IPP91.

    The ATTACHMENTS that I provided as part of this DISCUSSION are no longer visible to me.  If someone visits this discussion on their way to resolving an issue, can they see the original ATTACHMENTS or are they only getting part of the history?

    Thanks again.

    -- Matt
Sign In or Register to comment.